Bug 4608 – std.string.chomp documentation mismatch implementation

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-08-09T14:43:00Z
Last change time
2012-10-21T21:26:07Z
Assigned to
andrei
Creator
simendsjo

Comments

Comment #0 by simendsjo — 2010-08-09T14:43:53Z
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; }
Comment #1 by yao.gomez — 2012-02-05T21:18:12Z
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"); } ------