bug in std.string.replace
Ant
duitoolkit at yahoo.ca
Mon Feb 20 14:10:05 PST 2006
std.string.replace needs to check if char[]from is empty, for instance:
char[] replace(char[] s, char[] from, char[] to)
{
char[] p;
if ( from.length == 0 )
{
p = s.dup;
}
else
{
int i;
int istart;
//printf("replace('%.*s','%.*s','%.*s')\n", s, from, to);
istart = 0;
while (istart < s.length)
{
i = std.string.find(s[istart .. s.length], from);
if (i == -1)
{
p ~= s[istart .. s.length];
break;
}
p ~= s[istart .. istart + i];
p ~= to;
istart += i + from.length;
}
}
return p;
}
More information about the Digitalmars-d-bugs
mailing list