tabs

Returns a range of *spaces* equal to that of num tabs (\t).

Use std.conv.to or std.conv.text or similar to flatten to a string.

@safe pure nothrow @nogc
tabs
(
uint spaces = 4
)
(
const int num
)

Parameters

spaces

How many spaces make up a tab.

num int

How many tabs we want.

Return Value

Type: auto

A range of whitespace equalling (num * spaces) spaces.

Examples

string indentation = 2.tabs.text;
assert((indentation == "        "), `"` ~  indentation ~ `"`);
string smallIndent = 1.tabs!2.text;
assert((smallIndent == "  "), `"` ~  smallIndent ~ `"`);
import std.array : Appender;
import std.conv : to;
import std.exception : assertThrown;
import std.format : formattedWrite;
import std.algorithm.comparison : equal;
import core.exception : AssertError;

auto one = 1.tabs!4;
auto two = 2.tabs!3;
auto three = 3.tabs!2;
auto zero = 0.tabs;

assert(one.equal("    "), one.to!string);
assert(two.equal("      "), two.to!string);
assert(three.equal("      "), three.to!string);
assert(zero.equal(string.init), zero.to!string);

assertThrown!AssertError((-1).tabs);

Appender!(char[]) sink;
sink.formattedWrite("%sHello world", 2.tabs!2);
assert((sink.data == "    Hello world"), sink.data);

Meta