View source code
Display the source code in std/string.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

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

NameDescription
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

NameDescription
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

License

Boost License 1.0.