www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4608] New: std.string.chomp documentation mismatch implementation

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4608

           Summary: std.string.chomp documentation mismatch implementation
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: simen.endsjo pandavre.com



PDT ---
The documentation says
/*******************************************
 * Returns s[] sans trailing delimiter[], if any.
 * If delimiter[] is null, removes trailing CR, LF, or CRLF, if any.
 */ 

The implementation on the other hand returns the input string if delimiter is
null. So either the documentation or the implementation needs to be fixed.
If the implementation should work like the documentation, it could be something
like this:

C[] chomp(C, C1)(C[] s, in C1[] delimiter)
{
    if (delimiter == null)
      return chomp(s);
    else if (endsWith(s, delimiter))
      return s[0 .. $ - delimiter.length];
    else
      return s;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 09 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4608


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4608


Yao Gomez <yao.gomez gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yao.gomez gmail.com



DMD 2.058HEAD. With this example, all the assertions fail.

------
import std.string, std.stdio, std.conv;

void main()
{
    auto foo = "foobar\n\r\n\n";
    auto baz = chomp(foo);
    auto bar = chomp(foo, "");
    auto soz = chomp(foo, "\n\r");

    assert( baz == "foobar");
    assert( bar == "foobar");
    assert( soz == "foobar");
}
------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 05 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4608


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED


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