outdent

Removes one level of indentation from a multi-line string.

This uniformly outdents the text as much as possible. Whitespace-only lines are always converted to blank lines.

Does not allocate memory if it does not throw.

  1. S outdent(S str)
    @safe pure
    S
    outdent
    (
    S
    )
    (
    S str
    )
  2. S[] outdent(S[] lines)

Parameters

str S

multi-line string

Return Value

Type: S

outdented string

Throws

StringException if indentation is done with different sequences of whitespace characters.

Examples

    enum pretty = q{
       import std.stdio;
       void main() {
           writeln("Hello");
       }
    }.outdent();

    enum ugly = q{
import std.stdio;
void main() {
    writeln("Hello");
}
};

    assert(pretty == ugly);

Meta