www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - 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;
}
Feb 20 2006