outdent

Removes one level of indentation from an array of single-line strings.

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

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

Parameters

lines S[]

array of single-line strings

Return Value

Type: S[]

lines[] is rewritten in place with outdented lines

Throws

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

Examples

auto str1 = [
    "    void main()\n",
    "    {\n",
    "        test();\n",
    "    }\n"
];
auto str1Expected = [
    "void main()\n",
    "{\n",
    "    test();\n",
    "}\n"
];
assert(str1.outdent == str1Expected);

auto str2 = [
    "void main()\n",
    "    {\n",
    "            test();\n",
    "    }\n"
];
assert(str2.outdent == str2);

Meta