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.

Function std.string.detabber

Replace each tab character in r with the number of spaces necessary to align the following character at the next tab stop.

Prototype

auto detabber(Range)(
  Range r,
  size_t tabSize = 8
)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range));

Parameters

NameDescription
r string or forward range
tabSize distance between tab stops

Returns

lazy forward range with tabs replaced with spaces

Example

import std.array;

assert(detabber(" \n\tx", 9).array == " \n         x");

Example

import std.utf;
import std.array;

assert(detabber(" \u2029\t".byChar, 9).array == " \u2029         ");
auto r = "hel\tx".byWchar.detabber();
assert(r.front == 'h' && r.front == 'h');
auto s = r.save;
r.popFront();
r.popFront();
assert(r.front == 'l');
assert(s.front == 'h');

Authors

Walter Bright, Andrei Alexandrescu, and Jonathan M Davis

License

Boost License 1.0.

Comments