Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1555

Show
Ignore:
Timestamp:
05/26/10 05:59:30 (15 years ago)
Author:
rsinfu
Message:

Fixed bugzilla 3786: bug in std.string.removechars.
Thanks to Igor Lesik for the fix!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/changelog.dd

    r1554 r1555  
    1010    $(LI std.traits: Added templates to get compile-time information about functions.) 
    1111    $(LI std.typecons: Added tie and AutoImplement.) 
    1212    ) 
    1313    $(BUGSFIXED 
    1414    $(LI $(BUGZILLA 2738): Rebindable should work for interfaces.) 
    1515    $(LI $(BUGZILLA 2835): std.socket.TcpSocket doesn't actually connect) 
    1616    $(LI $(BUGZILLA 3088): std.xml.check() fails on xml comments) 
    1717    $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 
    1818    $(LI $(BUGZILLA 3465): isIdeographic can be wrong in std.xml) 
    1919    $(LI $(BUGZILLA 3653): Problem sorting array of Rebindable) 
     20    $(LI $(BUGZILLA 3786): bug in std.string.removechars) 
    2021    $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 
    2122    $(LI $(BUGZILLA 3880): std.regex functions with const/immutable Regex object) 
    2223    $(LI $(BUGZILLA 4109): writeln doesn't work with empty static array) 
    2324    $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 
    2425    $(LI $(BUGZILLA 4228): std.array.replace contains 2 bugs) 
    2526    $(LI $(BUGZILLA 4219): hasAliasing does not care about immutable) 
    2627    ) 
    2728) 
    2829 
    2930<div id=version> 
  • trunk/phobos/std/string.d

    r1542 r1555  
    28062806} 
    28072807 
    28082808 
    28092809/******************************************** 
    28102810 * Return string that is s with all characters removed that match pattern. 
    28112811 */ 
    28122812 
    28132813string removechars(string s, in string pattern) 
    28142814{ 
    28152815    char[] r; 
    2816     bool changed; 
    2817  
    2818     //writefln("removechars(%s, %s)", s, pattern); 
     2816    bool changed = false; 
     2817 
    28192818    foreach (size_t i, dchar c; s) 
    28202819    { 
    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; 
    28252826        } 
    28262827        if (changed) 
    28272828        { 
    28282829            std.utf.encode(r, c); 
    28292830        } 
    28302831    } 
    2831     return assumeUnique(r); 
    2832 
    2833  
     2832    return (changed? assumeUnique(r) : s); 
     2833
    28342834unittest 
    28352835{ 
    28362836    debug(string) printf("std.string.removechars.unittest\n"); 
    28372837 
    28382838    string r; 
    28392839 
    28402840    r = removechars("abc", "a-c"); 
    28412841    assert(r.length == 0); 
    28422842    r = removechars("hello world", "or"); 
    28432843    assert(r == "hell wld"); 
    28442844    r = removechars("hello world", "d"); 
    28452845    assert(r == "hello worl"); 
     2846    r = removechars("hah", "h"); 
     2847    assert(r == "a"); 
    28462848} 
    28472849 
    28482850 
    28492851/*************************************************** 
    28502852 * Return string where sequences of a character in s[] from pattern[] 
    28512853 * are replaced with a single instance of that character. 
    28522854 * If pattern is null, it defaults to all characters. 
    28532855 */ 
    28542856 
    28552857string squeeze(string s, string pattern = null)