normalize

Unindents, strips whitespace-only lines from top and bottom, and strips trailing whitespace from eash line. (Also converts Windows "\r\n" line endings to Unix "\n" line endings.)

See also the documentation for unindent().

Good for making easily-readable multi-line string literals without leaving extra indents and whitespace in the resulting string:

Do this:

void foo()
{
	enum codeStr = q{
		// Written in the D Programming Langauge
		// by John Doe

		int main()
		{
			return 0;
		}
	}.normalize();
}

Instead of this:

void foo()
{
	enum codeStr = 
q{// Written in the D Programming Langauge
// by John Doe

int main()
{
	return 0;
}};
}

The resulting string is exactly the same.

  1. T normalize(T str)
  2. T[] normalize(T[] lines)
    T[]
    normalize
    (
    T
    )
    (
    T[] lines
    )
    if (
    isSomeString!T
    )

Meta