std.string.chomp error
bearophile
bearophileHUGS at lycos.com
Mon Aug 9 10:34:51 PDT 2010
Lars T. Kyllingstad:
> Either that, or the documentation for it needs to be changed. Anyway, it
> would be great if you'd report this.
A really basic unit testing is able to catch an error like this. This means Phobos needs more unit tests.
Stuff that may be added to that unittest:
import std.stdio, std.string;
void main() {
assert(chomp("hello") == "hello");
assert(chomp("hello\n") == "hello");
assert(chomp("hello\r\n") == "hello");
assert(chomp("hello", "") == "hello");
assert(chomp("hello\n", "") == "hello");
assert(chomp("hello\r\n", "") == "hello");
assert(chomp("hello\r\n", "") == "hello");
assert(chomp("helloxxx", "x") == "helloxx");
}
But instead of:
if (delimiter == null)
Is better to write:
if (delimiter.length == 0)
Or:
if (delimiter == "")
See http://d.puremagic.com/issues/show_bug.cgi?id=3889
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list