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

Split an array or slicable range of characters into a range of lines using '\r', '\n', '\v', '\f', "\r\n", std.uni.lineSep, std.uni.paraSep and '\u0085' (NEL) as delimiters. If keepTerm is set to KeepTerminator.yes, then the delimiter is included in the slices returned.

Does not throw on invalid UTF; such is simply passed unchanged to the output.

Adheres to Unicode 7.0.

Does not allocate memory.

Prototype

auto lineSplitter(std.typecons.Flag!("keepTerminator").Flag keepTerm, Range)(
  Range r
)
if (hasSlicing!Range && hasLength!Range || isSomeString!Range);

Parameters

NameDescription
r array of chars, wchars, or dchars or a slicable range
keepTerm whether delimiter is included or not in the results

Returns

range of slices of the input range r

See Also

splitLines std.algorithm.splitter std.regex.splitter

Example

auto s = "\rpeter\n\rpaul\r\njerry\u2028ice\u2029cream\n\nsunday\nmon\u2030day\n";
auto lines = s.lineSplitter();
static immutable witness = ["", "peter", "", "paul", "jerry", "ice", "cream", "", "sunday", "mon\u2030day"];
uint i;
foreach (line; lines)
{
    assert(line == witness[i++]);
}
assert(i == witness.length);

Authors

Walter Bright, Andrei Alexandrescu, and Jonathan M Davis

License

Boost License 1.0.

Comments