Changeset 1212
- Timestamp:
- 07/04/09 03:14:33 (3 years ago)
- Files:
-
- trunk/phobos/std/regex.d (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/regex.d
r1111 r1212 1517 1517 } 1518 1518 1519 /** ***************************1519 /** 1520 1520 $(D RegexMatch) is the type returned by a call to $(D match). It 1521 1521 stores the matching state and can be inspected and iterated. … … 1571 1571 } 1572 1572 1573 // ref auto opSlice() 1574 // { 1575 // return this; 1576 // } 1577 1573 1578 /** 1574 1579 Range primitives that allow incremental matching against a string. … … 1593 1598 --- 1594 1599 */ 1595 1596 ref auto opSlice()1597 {1598 return this;1599 }1600 1601 1600 bool empty() const 1602 1601 { … … 2662 2661 { 2663 2662 case '&': 2664 result ~= input[pmatch[0].startIdx .. pmatch[0].endIdx]; 2663 result ~= to!string( 2664 input[pmatch[0].startIdx .. pmatch[0].endIdx]); 2665 2665 break; 2666 2666 … … 2675 2675 if (j <= engine.re_nsub && pmatch[j].startIdx 2676 2676 != pmatch[j].endIdx) 2677 result ~= 2678 input[pmatch[j].startIdx .. pmatch[j].endIdx];2677 result ~= to!string 2678 (input[pmatch[j].startIdx .. pmatch[j].endIdx]); 2679 2679 break; 2680 2680 } … … 2917 2917 { 2918 2918 _input = input; 2919 _match = match(_input, separator); 2919 if (_input.empty) 2920 { 2921 // there is nothing to match at all, make _offset > 0 2922 _offset = 1; 2923 } 2924 else 2925 { 2926 _match = match(_input, separator); 2927 } 2920 2928 } 2921 2929 … … 2934 2942 { 2935 2943 //write("[");scope(success) writeln("]"); 2936 assert( _offset <= _match.pre.length2944 assert(!empty && _offset <= _match.pre.length 2937 2945 && _match.pre.length <= _input.length); 2938 2946 return _input[_offset .. min($, _match.pre.length)]; … … 2941 2949 bool empty() 2942 2950 { 2943 return _offset > =_input.length;2951 return _offset > _input.length; 2944 2952 } 2945 2953 … … 2951 2959 { 2952 2960 // No more separators, work is done here 2953 _offset = _input.length ;2961 _offset = _input.length + 1; 2954 2962 } 2955 2963 else … … 2975 2983 auto s1 = ", abc, de, fg, hi, "; 2976 2984 auto sp1 = splitter(s1, regex(", *")); 2977 auto w1 = ["", "abc", "de", "fg", "hi" ];2985 auto w1 = ["", "abc", "de", "fg", "hi", ""]; 2978 2986 assert(equal(sp1, w1[])); 2979 2987 … … 2989 2997 char[] s1 = ", abc, de, fg, hi, ".dup; 2990 2998 auto sp2 = splitter(s1, regex(", *")); 2999 } 3000 3001 String[] split(String)(String input, Regex!(char) rx) 3002 { 3003 Appender!(String[]) a; 3004 foreach (e; splitter(input, rx)) 3005 { 3006 a.put(e); 3007 } 3008 return a.data; 3009 } 3010 3011 unittest 3012 { 3013 auto s1 = ", abc, de, fg, hi, "; 3014 auto w1 = ["", "abc", "de", "fg", "hi", ""]; 3015 assert(equal(split(s1, regex(", *")), w1[])); 2991 3016 } 2992 3017
