http://d.puremagic.com/issues/show_bug.cgi?id=3786

           Summary: bug in std.string.removechars
           Product: D
           Version: 2.039
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: curo...@yahoo.com
                CC: curo...@yahoo.com


--- Comment #0 from Igor Lesik <curo...@yahoo.com> 2010-02-09 03:24:26 PST ---
I do not understand how std.string.removechars could pass the unittest. It does
not work for me and its implementation looks buggy, imho.

    foreach (size_t i, dchar c; s)
    {
        if (inPattern(c, pattern)) continue; <-- here we must check change flag

        if (!changed)
        {   changed = true;
            r = s[0 .. i].dup; <----- Why 0? what if we skipped 1st char?

The problem could be fixed by replacing [0..i] with [i..i], but then the
original idea to optimize some cases does not work at all. Speculating what the
author had in mind writing this code, I would rewrite it this way (passes the
unittest btw):

    foreach (size_t i, dchar c; s)
    {
        if (inPattern(c, pattern)) {
                if (!changed)
                {   changed = true;
                    r = s[0 .. i].dup;
                }
                continue;
        }
        if (changed)
        {
            std.utf.encode(r, c);
        }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to