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 Yes.keepTerminator, 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.

  1. auto lineSplitter(Range r)
    lineSplitter
    (
    KeepTerminator keepTerm = No.keepTerminator
    Range
    )
    (
    Range r
    )
    if (
    hasSlicing!Range &&
    hasLength!Range
    &&
    &&
    )
  2. auto lineSplitter(C[] r)

Parameters

r Range

array of chars, wchars, or dchars or a slicable range

keepTerm

whether delimiter is included or not in the results

Return Value

Type: auto

range of slices of the input range r

Examples

import std.array : array;

string s = "Hello\nmy\rname\nis";

/* notice the call to 'array' to turn the lazy range created by
lineSplitter comparable to the string[] created by splitLines.
*/
assert(lineSplitter(s).array == splitLines(s));
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);

See Also

Meta