Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

crash of tango.text.regex

Moderators: kris

Posted: 11/29/09 07:27:38

When I do

import tango.io.Stdout;
import tango.text.Regex;

void main()
{
    foreach(m; Regex("b").search("abcdefghijklmnopqrstumwxyz"))
    {
        Stdout.formatln("{}[{}]{}", m.pre, m.match(0), m.post);
        Stdout.formatln("{}[{}]{}", m.pre, m.match(1), m.post);
        Stdout.formatln("{}[{}]{}", m.pre, m.match(2), m.post);
        Stdout.formatln("{}[{}]{}", m.pre, m.match(3), m.post);
        Stdout.formatln("{}[{}]{}", m.pre, m.match(4), m.post);
    }
}

I get

tango.core.Exception.ArrayBoundsException@tango/text/Regex.d(3985): Array index out of bounds

so I try modify RegExpT.match like this:

    char_t[] match(uint index)
    {
        // fix it
        // if ( index > tdfa_.num_tags )
        if ( index >= tdfa_.num_tags )
            return null;
        int start   = last_start_+registers_[index*2],
            end     = last_start_+registers_[index*2+1];
        if ( start >= 0 && start < end && end <= input_.length )
            return input_[start .. end];
        return null;
    }

It is OK.

There are no responses to display.