std.string.outdent
- multiple declarations
Function outdent
Removes one level of indentation from a multi-line string.
S outdent(S)
(
S str
) pure @safe
if (isSomeString!S);
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.
Parameters
Name | Description |
---|---|
str | multi-line string |
Returns
outdented string
Throws
StringException if indentation is done with different sequences of whitespace characters.
Example
enum pretty = q{
import std.stdio;
void main() {
writeln("Hello");
}
} .outdent();
enum ugly = q{
import std.stdio;
void main() {
writeln("Hello");
}
};
writeln(pretty); // ugly
Function outdent
Removes one level of indentation from an array of single-line strings.
S[] outdent(S)
(
S[] lines
) pure @safe
if (isSomeString!S);
This uniformly outdents the text as much as possible. Whitespace-only lines are always converted to blank lines.
Parameters
Name | Description |
---|---|
lines | array of single-line strings |
Returns
lines[] is rewritten in place with outdented lines
Throws
StringException if indentation is done with different sequences of whitespace characters.
Example
auto str1 = [
" void main()\n",
" {\n",
" test();\n",
" }\n"
];
auto str1Expected = [
"void main()\n",
"{\n",
" test();\n",
"}\n"
];
writeln(str1 .outdent); // str1Expected
auto str2 = [
"void main()\n",
" {\n",
" test();\n",
" }\n"
];
writeln(str2 .outdent); // str2
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis