indentInto

Indents lines in a string into an output range sink with the supplied number of tabs.

@safe
void
indentInto
(
uint spaces = 4
Sink
)
(
const string wallOfText
,
auto ref Sink sink
,
const uint numTabs = 1
,
const uint skip = 0
)

Parameters

spaces

How many spaces in an indenting tab.

wallOfText string

String to indent the individual lines of.

sink Sink

Output range to fill with the indented lines.

numTabs uint

Optional amount of tabs to indent with, default 1.

skip uint

How many lines to skip indenting.

Examples

    import std.array : Appender;

    Appender!(char[]) sink;

    immutable string_ =
"Lorem ipsum
sit amet
I don't remember
any more offhand
so shrug";

    string_.indentInto(sink);
    assert((sink.data ==
"    Lorem ipsum
    sit amet
    I don't remember
    any more offhand
    so shrug"), '\n' ~ sink.data);

    sink.clear();
    string_.indentInto!3(sink, 2);
    assert((sink.data ==
"      Lorem ipsum
      sit amet
      I don't remember
      any more offhand
      so shrug"), '\n' ~ sink.data);

    sink.clear();
    string_.indentInto(sink, 0);
    assert((sink.data ==
"Lorem ipsum
sit amet
I don't remember
any more offhand
so shrug"), '\n' ~ sink.data);