indent

Indents lines in a string with the supplied number of tabs. Returns a newly allocated string.

@safe pure
string
indent
(
uint spaces = 4
)
(
const string wallOfText
,
const uint numTabs = 1
,
const uint skip = 0
)

Parameters

spaces

How many spaces make up a tab.

wallOfText string

String to indent the lines of.

numTabs uint

Amount of tabs to indent with, default 1.

skip uint

How many lines to skip indenting.

Return Value

Type: string

A string with all the lines of the original string indented.

Examples

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

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

    immutable indentedTwo = string_.indent(2);
    assert((indentedTwo ==
"        Lorem ipsum
        sit amet
        I don't remember
        any more offhand
        so shrug"), '\n' ~ indentedTwo);

    immutable indentedZero = string_.indent(0);
    assert((indentedZero ==
"Lorem ipsum
sit amet
I don't remember
any more offhand
so shrug"), '\n' ~ indentedZero);

    immutable indentedSkipTwo = string_.indent(1, 2);
    assert((indentedSkipTwo ==
"Lorem ipsum
sit amet
    I don't remember
    any more offhand
    so shrug"), '\n' ~ indentedSkipTwo);