View mode: basic / threaded / horizontal-split · Log in · Help
March 28, 2008
std.string.removechars does not remove leading chars
This is supposed to be a bug report! :)

--------------------------------------
import std.string;

int main( char[][] args )
{
	// Construct a string with some whitespaces.
	string stripMyWhitespaces = "\t\t\tHello _World   !\t\t\t";

	// Strip the whitespaces using "removechars". This worked in GDC/D1.0 without problems.
	string helloWorld = removechars( stripMyWhitespaces, whitespace );

	// Ensure '\t' is in "whitespace".
	assert( find( whitespace, "\t" ) != -1 );

	// "helloWorld" equals "\t\t\tHello_World!", not "Hello_World!", assert fails. Leading '\t's are not removed.
	assert( helloWorld == "Hello_World!" );

	return 0;
}

--------------------------------------

In the above example, the second assert fails; not just with '\t', but also with any other char literal. This behaviour is not documented, so it's probably a bug indeed.

I came across this bug while porting from GDC to D2.012. Looking at the phobos sources of both compilers, it seems like the implementation of "removechars" changed (don't ask me why!).

Andreas Jung
Top | Discussion index | About this forum | D home