Changeset 1555
- Timestamp:
- 05/26/10 05:59:30 (15 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (1 diff)
- trunk/phobos/std/string.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r1554 r1555 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 2738): Rebindable should work for interfaces.) 15 15 $(LI $(BUGZILLA 2835): std.socket.TcpSocket doesn't actually connect) 16 16 $(LI $(BUGZILLA 3088): std.xml.check() fails on xml comments) 17 17 $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 18 18 $(LI $(BUGZILLA 3465): isIdeographic can be wrong in std.xml) 19 19 $(LI $(BUGZILLA 3653): Problem sorting array of Rebindable) 20 $(LI $(BUGZILLA 3786): bug in std.string.removechars) 20 21 $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 21 22 $(LI $(BUGZILLA 3880): std.regex functions with const/immutable Regex object) 22 23 $(LI $(BUGZILLA 4109): writeln doesn't work with empty static array) 23 24 $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 24 25 $(LI $(BUGZILLA 4228): std.array.replace contains 2 bugs) 25 26 $(LI $(BUGZILLA 4219): hasAliasing does not care about immutable) 26 27 ) 27 28 ) 28 29 29 30 <div id=version> trunk/phobos/std/string.d
r1542 r1555 2806 2806 } 2807 2807 2808 2808 2809 2809 /******************************************** 2810 2810 * Return string that is s with all characters removed that match pattern. 2811 2811 */ 2812 2812 2813 2813 string removechars(string s, in string pattern) 2814 2814 { 2815 2815 char[] r; 2816 bool changed; 2817 2818 //writefln("removechars(%s, %s)", s, pattern); 2816 bool changed = false; 2817 2819 2818 foreach (size_t i, dchar c; s) 2820 2819 { 2821 if (inPattern(c, pattern)) continue; 2822 if (!changed) 2823 { changed = true; 2824 r = s[0 .. i].dup; 2820 if (inPattern(c, pattern)){ 2821 if (!changed) 2822 { changed = true; 2823 r = s[0 .. i].dup; 2824 } 2825 continue; 2825 2826 } 2826 2827 if (changed) 2827 2828 { 2828 2829 std.utf.encode(r, c); 2829 2830 } 2830 2831 } 2831 return assumeUnique(r); 2832 } 2833 2832 return (changed? assumeUnique(r) : s); 2833 } 2834 2834 unittest 2835 2835 { 2836 2836 debug(string) printf("std.string.removechars.unittest\n"); 2837 2837 2838 2838 string r; 2839 2839 2840 2840 r = removechars("abc", "a-c"); 2841 2841 assert(r.length == 0); 2842 2842 r = removechars("hello world", "or"); 2843 2843 assert(r == "hell wld"); 2844 2844 r = removechars("hello world", "d"); 2845 2845 assert(r == "hello worl"); 2846 r = removechars("hah", "h"); 2847 assert(r == "a"); 2846 2848 } 2847 2849 2848 2850 2849 2851 /*************************************************** 2850 2852 * Return string where sequences of a character in s[] from pattern[] 2851 2853 * are replaced with a single instance of that character. 2852 2854 * If pattern is null, it defaults to all characters. 2853 2855 */ 2854 2856 2855 2857 string squeeze(string s, string pattern = null)
