February 21, 2006 bug in std.string.replace | ||||
---|---|---|---|---|
| ||||
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; } |
Copyright © 1999-2021 by the D Language Foundation