View source code Display the source code in std/string.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

std.string.outdent - multiple declarations

Function 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.

Prototype

S[] outdent(S)(
  S[] lines
) pure @safe
if (isSomeString!S);

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.

Function 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.

Prototype

S outdent(S)(
  S str
) pure @safe
if (isSomeString!S);

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");
}
};

assert(pretty == ugly);

Authors

Walter Bright, Andrei Alexandrescu, and Jonathan M Davis

License

Boost License 1.0.

Comments