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

Changeset 3699

Show
Ignore:
Timestamp:
07/02/08 17:12:10 (3 months ago)
Author:
jascha
Message:

- fixed #1019 #1061 #1075 #1078 #1101

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/text/Regex.d

    r3487 r3699  
    19511951 
    19521952        char_t  last; 
    1953         bool    have_range_start; 
     1953        bool    have_range_start, 
     1954                first_char = true; 
    19541955        for ( ; !endOfPattern && peekPattern != ']'; ) 
    19551956        { 
     
    19581959            { 
    19591960                case '-': 
     1961                    if ( first_char ) { 
     1962                        trans.predicate.appendInput(range_t(c)); 
     1963                        break; 
     1964                    } 
    19601965                    if ( !have_range_start ) 
    1961                         throw new RegExpException("Missing range start for '-' operator ater \""~Utf.toString(pattern)~"\""); 
     1966                        throw new RegExpException("Missing range start for '-' operator after \""~Utf.toString(pattern)~"\""); 
    19621967                    else if ( endOfPattern || peekPattern == ']' ) 
    1963                         throw new RegExpException("Missing range end for '-' operator ater \""~Utf.toString(pattern)~"\""); 
     1968                        throw new RegExpException("Missing range end for '-' operator after \""~Utf.toString(pattern)~"\""); 
    19641969                    else { 
    19651970                        c = readPattern; 
     
    19921997                    have_range_start = true; 
    19931998            } 
     1999            first_char = false; 
    19942000        } 
    19952001        if ( !endOfPattern ) 
     
    26572663        } 
    26582664 
     2665        debug 
     2666        { 
     2667            foreach ( ref v; registers ) 
     2668            { 
     2669                if ( (v in regNums) !is null ) 
     2670                    v = regNums[v]; 
     2671            } 
     2672        } 
     2673 
    26592674        minimizeDFA; 
    26602675 
     
    33473362                if ( te.nfa_state.index != fe.nfa_state.index ) 
    33483363                    continue; 
     3364                if ( fe.tags.length != te.tags.length ) 
     3365                    return false; 
    33493366                foreach ( tag, findex; fe.tags ) 
    33503367                { 
     
    39763993        char_t[] tmp = input; 
    39773994        if ( output_buffer.length <= 0 ) 
    3978             output_buffer = new char_t[input.length]; 
     3995            output_buffer = new char_t[input.length+replacement.length]; 
    39793996        output_buffer.length = 0; 
    39803997 
    39813998        foreach ( r; search(input) ) 
     3999        { 
     4000            tmp = pre; 
     4001            if ( tmp.length > last_start_ ) 
     4002                output_buffer ~= tmp[last_start_ .. $]; 
     4003            output_buffer ~= replacement; 
     4004            tmp = post; 
     4005        } 
     4006        output_buffer ~= tmp; 
     4007        return output_buffer; 
     4008    } 
     4009 
     4010    /********************************************************************************************** 
     4011        Returns a copy of the input with the last match replaced by replacement. 
     4012    **********************************************************************************************/ 
     4013    char_t[] replaceLast(char_t[] input, char_t[] replacement, char_t[] output_buffer=null) 
     4014    { 
     4015        char_t[] tmp_pre, tmp_post; 
     4016        if ( output_buffer.length <= 0 ) 
     4017            output_buffer = new char_t[input.length+replacement.length]; 
     4018        output_buffer.length = 0; 
     4019 
     4020        foreach ( r; search(input) ) { 
     4021            tmp_pre = pre; 
     4022            tmp_post = post; 
     4023        } 
     4024 
     4025        if ( tmp_pre !is null || tmp_post !is null ) { 
     4026            output_buffer ~= tmp_pre; 
     4027            output_buffer ~= replacement; 
     4028            output_buffer ~= tmp_post; 
     4029        } 
     4030        else 
     4031            output_buffer ~= input; 
     4032 
     4033        return output_buffer; 
     4034    } 
     4035 
     4036    /********************************************************************************************** 
     4037        Returns a copy of the input with the first match replaced by replacement. 
     4038    **********************************************************************************************/ 
     4039    char_t[] replaceFirst(char_t[] input, char_t[] replacement, char_t[] output_buffer=null) 
     4040    { 
     4041        char_t[] tmp = input; 
     4042        if ( output_buffer.length <= 0 ) 
     4043            output_buffer = new char_t[input.length+replacement.length]; 
     4044        output_buffer.length = 0; 
     4045 
     4046        if ( test(input) ) 
    39824047        { 
    39834048            tmp = pre;