Changeset 3699
- Timestamp:
- 07/02/08 17:12:10 (3 months ago)
- Files:
-
- trunk/tango/text/Regex.d (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tango/text/Regex.d
r3487 r3699 1951 1951 1952 1952 char_t last; 1953 bool have_range_start; 1953 bool have_range_start, 1954 first_char = true; 1954 1955 for ( ; !endOfPattern && peekPattern != ']'; ) 1955 1956 { … … 1958 1959 { 1959 1960 case '-': 1961 if ( first_char ) { 1962 trans.predicate.appendInput(range_t(c)); 1963 break; 1964 } 1960 1965 if ( !have_range_start ) 1961 throw new RegExpException("Missing range start for '-' operator a ter \""~Utf.toString(pattern)~"\"");1966 throw new RegExpException("Missing range start for '-' operator after \""~Utf.toString(pattern)~"\""); 1962 1967 else if ( endOfPattern || peekPattern == ']' ) 1963 throw new RegExpException("Missing range end for '-' operator a ter \""~Utf.toString(pattern)~"\"");1968 throw new RegExpException("Missing range end for '-' operator after \""~Utf.toString(pattern)~"\""); 1964 1969 else { 1965 1970 c = readPattern; … … 1992 1997 have_range_start = true; 1993 1998 } 1999 first_char = false; 1994 2000 } 1995 2001 if ( !endOfPattern ) … … 2657 2663 } 2658 2664 2665 debug 2666 { 2667 foreach ( ref v; registers ) 2668 { 2669 if ( (v in regNums) !is null ) 2670 v = regNums[v]; 2671 } 2672 } 2673 2659 2674 minimizeDFA; 2660 2675 … … 3347 3362 if ( te.nfa_state.index != fe.nfa_state.index ) 3348 3363 continue; 3364 if ( fe.tags.length != te.tags.length ) 3365 return false; 3349 3366 foreach ( tag, findex; fe.tags ) 3350 3367 { … … 3976 3993 char_t[] tmp = input; 3977 3994 if ( output_buffer.length <= 0 ) 3978 output_buffer = new char_t[input.length ];3995 output_buffer = new char_t[input.length+replacement.length]; 3979 3996 output_buffer.length = 0; 3980 3997 3981 3998 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) ) 3982 4047 { 3983 4048 tmp = pre;












