[Mono-list] Bug in Regex

Jonathan Stowe gellyfish@gellyfish.com
Sun, 12 May 2002 12:29:13 +0100 (BST)


On Sun, 12 May 2002, Dan Lewis wrote:

> Stefan Matthias Aust wrote:
> > Well, every way I try to go for my wiki project seems to be blocked or at
> > least "bumpy".  The following example throws an ArgumentOutOfRangeException
> > on mono (last compiling cvs version):
>
> Fixed in CVS.
>

I'm not so sure that it is :

Unhandled exception System.ArgumentOutOfRangeException Argument is out of
range.#0: 0x00018 throw      in System.String::Substring ([4] [-1] )
#1: 0x00028 callvirt   in System.Text.RegularExpressions.Regex::Split
([0x80c3ec0] [2147483647] [0] )
#2: 0x00008 call       in System.Text.RegularExpressions.Regex::Split
([0x80c3ec0] )
#3: 0x0000f callvirt   in .x::Main ()


This is freshly checked out sources this morning.


Forgive me if am barking up the wrong tree but isnt the

               while (count -- > 0 && m.Success) {
                          splits.Add (input.Substring (ptr, m.Index - ptr));
                          ptr = m.Index + m.Length;
               }

in regex.cs always going to result in ptr being larger than m.Index (and
thus an out of range exception) the second time around the loop ?  Again I
might be totally wrong but shouldn't there be a Match() within the loop ?

Although seeing what Stefan is trying to do wouldn't something like :

using System;

class Foo
{
    public static void Main()
    {
       String myString = "This=foo;is=a&a=b;test=1";

       Char[] gh = {';','&'};


       String[] substrings = myString.Split(gh);

       foreach (String foo in substrings)
       {
          System.Console.WriteLine(foo);
       }
    }

}

Cut out the middleman (System.Text.Regex in this case :)


/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |