Bug 3704 – split(char[],char[]) is broken for delimiters greater than a single character
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2010-01-13T21:49:00Z
Last change time
2014-02-07T14:04:34Z
Assigned to
nobody
Creator
nyphbl8d
Comments
Comment #0 by nyphbl8d — 2010-01-13T21:49:06Z
There are no fewer than 4 critical errors in the latest implementation of split in phobos for the code path that deals with delimiters of length > 1.
test code:
import std.stdio;
import std.string;
void main() {
foreach(item;"@match".split(" and ")) writefln("my data: %s",item);
}
Half of the problem is caused by using size_t (which is unsigned afaict) to capture the return value of find, which can be negative. This issue causes the following comparison to fail:
if (j == -1)
The other half is caused by not accounting for the fact that i can be greater than s.length, as well as equal. This causes the following comparison to fail to perform as expected:
if (i == s.length)
Comment #1 by andrej.mitrovich — 2011-05-24T21:34:17Z
Has this been fixed? I have no problem of using delimiters with sizes greater than 1:
This works:
import std.stdio;
import std.string;
void main()
{
foreach (item; "test test".split(" "))
{
writefln("my data: %s", item);
}
}
Comment #2 by bearophile_hugs — 2011-05-25T02:53:15Z
If this bug report doesn't become more clear, then I suggest to eventually close it.
Comment #3 by peter.alexander.au — 2014-02-07T14:04:34Z