splitter

fnauto splitter(alias pred = "a == b", Flag!"keepSeparators" keepSeparators = No.keepSeparators, Range, Separator)(Range r, Separator s) if (is(typeof(binaryFun!pred(r.front, s)) : bool) && ((hasSlicing!Range && hasLength!Range) || isNarrowString!Range))

Lazily splits a range using an element or range as a separator. Separator ranges can be any narrow string type or sliceable range type.

Two adjacent separators are considered to surround an empty element in the split range. Use filter!(a => !a.empty) on the result to compress empty elements.

The predicate is passed to binaryFun and accepts any callable function that can be executed via pred(element, s).

Note

If splitting a string on whitespace and token compression is desired,

consider using the splitter(r) overload.

Parameters

predThe predicate for comparing each element with the separator, defaulting to "a == b".
rThe input range to be split. Must support slicing and .length or be a narrow string type.
sThe element (or range) to be treated as the separator between range segments to be split.
keepSeparatorsThe flag for deciding if the separators are kept Constraints: The predicate pred needs to accept an element of r and the separator s.

Returns

An input range of the subranges of elements between separators. If r

is a forward range or bidirectional range, the returned range will be likewise. When a range is used a separator, bidirectionality isn't possible.

If keepSeparators is equal to Yes.keepSeparators the output will also contain the separators.

If an empty range is given, the result is an empty range. If a range with one separator is given, the result is a range with two empty elements.

See Also

- _splitter for a version that splits using a regular expression defined separator.
  • _split for a version that splits eagerly.
  • splitWhen, which compares adjacent elements instead of element against separator.
fnauto splitter(alias pred = "a == b", Flag!"keepSeparators" keepSeparators = No.keepSeparators, Range, Separator)(Range r, Separator s) if (is(typeof(binaryFun!pred(r.front, s.front)) : bool) && (hasSlicing!Range || isNarrowString!Range) && isForwardRange!Separator && (hasLength!Separator || isNarrowString!Separator))

ditto

fnauto splitter(alias isTerminator, Range)(Range r) if (isForwardRange!Range && is(typeof(unaryFun!isTerminator(r.front))))

Lazily splits a range r whenever a predicate isTerminator returns true for an element.

As above, two adjacent separators are considered to surround an empty element in the split range.

Parameters

rThe forward range to be split.
isTerminatorA unary predicate for deciding where to split the range.

Returns

A forward range of slices of the original range split by whitespace.
fnauto splitter(Range)(Range s) if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && !isConvertibleToString!Range && isSomeChar!(ElementEncodingType!Range))

Lazily splits the character-based range s into words, using whitespace as the delimiter.

This function is character-range specific and, contrary to splitter!(std.uni.isWhite), runs of whitespace will be merged together (no empty tokens will be produced).

Parameters

sThe character-based range to be split. Must be a string, or a random-access range of character types.

Returns

An input range of slices of

the original range split by whitespace.