Changeset 1545
- Timestamp:
- 05/23/10 11:52:53 (15 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (1 diff)
- trunk/phobos/std/regex.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r1544 r1545 7 7 8 8 $(WHATSNEW 9 9 $(LI std.functional: toDelegate now accepts callable(function pointers, delegates and objects implement opCall) ) 10 10 $(LI std.traits: Added templates to get compile-time information about functions.) 11 11 $(LI std.typecons: Added tie and AutoImplement.) 12 12 ) 13 13 $(BUGSFIXED 14 14 $(LI $(BUGZILLA 2835): std.socket.TcpSocket doesn't actually connect) 15 15 $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 16 16 $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 17 $(LI $(BUGZILLA 3880): std.regex functions with const/immutable Regex object) 17 18 $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 18 19 ) 19 20 ) 20 21 21 22 <div id=version> 22 23 $(UL 23 24 $(NEW 047) 24 25 $(NEW 046) 25 26 $(NEW 045) 26 27 $(NEW 044) trunk/phobos/std/regex.d
r1495 r1545 2699 2699 //------------------------------------------------------------------------------ 2700 2700 2701 2701 /** 2702 2702 Matches a string against a regular expression. This is the main entry 2703 2703 to the module's functionality. A call to $(D match(input, regex)) 2704 2704 returns a $(D RegexMatch) object that can be used for direct 2705 2705 inspection or for iterating over all matches (if the regular 2706 2706 expression was built with the "g" option). 2707 2707 */ 2708 2708 RegexMatch!(Range) match(Range, Engine)(Range r, Engine engine) 2709 if (is( Engine == Regex!(Unqual!(typeof(Range.init[0])))))2709 if (is(Unqual!Engine == Regex!(Unqual!(typeof(Range.init[0]))))) 2710 2710 { 2711 2711 return typeof(return)(engine, r); 2712 2712 } 2713 2713 2714 2714 RegexMatch!(Range) match(Range, E)(Range r, E[] engine, string opt = null) 2715 2715 //if (is(Engine == Regex!(Unqual!(ElementType!(Range))))) 2716 2716 { 2717 2717 return typeof(return)(regex(engine, opt), r); 2718 2718 } 2719 2719 … … 2781 2781 2782 2782 The replacement format can reference the matches using the $&, $$, 2783 2783 $', $`, $0 .. $99 notation: 2784 2784 2785 2785 --- 2786 2786 assert(replace("noon", regex("^n"), "[$&]") == "[n]oon"); 2787 2787 --- 2788 2788 */ 2789 2789 2790 2790 Range replace(Range, Engine, String)(Range input, Engine regex, String format) 2791 if (is( Engine == Regex!(Unqual!(typeof(Range.init[0])))))2791 if (is(Unqual!Engine == Regex!(Unqual!(typeof(Range.init[0]))))) 2792 2792 { 2793 2793 return RegexMatch!(Range)(regex, input).replaceAll(format); 2794 2794 } 2795 2795 2796 2796 unittest 2797 2797 { 2798 2798 debug(regex) printf("regex.sub.unittest\n"); 2799 2799 assert(replace("hello", regex("ll"), "ss") == "hesso"); 2800 2800 assert(replace("barat", regex("a"), "A") == "bArat"); 2801 2801 assert(replace("barat", regex("a", "g"), "A") == "bArAt"); … … 2900 2900 //------------------------------------------------------------------------------ 2901 2901 2902 2902 /** 2903 2903 Range that splits another range using a regular expression as a 2904 2904 separator. 2905 2905 2906 2906 Example: 2907 2907 ---- 2908 2908 auto s1 = ", abc, de, fg, hi, "; 2909 2909 assert(equal(splitter(s1, regex(", *")), 2910 ["", "abc", "de", "fg", "hi" ][]));2910 ["", "abc", "de", "fg", "hi", ""][])); 2911 2911 ---- 2912 2912 */ 2913 2913 struct Splitter(Range) 2914 2914 { 2915 2915 Range _input; 2916 2916 size_t _offset; 2917 2917 alias Regex!(Unqual!(typeof(Range.init[0]))) Rx; 2918 2918 // Rx _rx; 2919 2919 RegexMatch!(Range) _match; 2920 2920
