String line to remove characters from.
A new string with any control characters removed, or the original one unchanged if there were none.
{
immutable line = "abc\ndef";
immutable expected = "abcdef";
immutable actual = removeControlCharacters(line);
assert((actual == expected), actual);
}
{
immutable line = "\n\t\r\0";
immutable expected = "";
immutable actual = removeControlCharacters(line);
assert((actual == expected), actual);
}
{
immutable line = "";
immutable expected = "";
immutable actual = removeControlCharacters(line);
assert((actual == expected), actual);
}
{
immutable line = "nothing to escape";
immutable expected = "nothing to escape";
immutable actual = removeControlCharacters(line);
assert((actual == expected), actual);
assert(line is actual); // No new string was allocated
}
Removes the control characters '\n', '\t', '\r' and '\0' from a string. Does not allocate a new string if there was nothing to remove.