The OpenD Programming Language

Splitter

Splits a string r using a regular expression pat as a separator.

struct Splitter (
Flag!"keepSeparators" keepSeparators = No.keepSeparators
Range
alias RegEx = Regex
) if (
isSomeString!Range &&
isRegexFor!(RegEx, Range)
) {}

Members

Functions

popFront
void popFront()
empty
bool empty [@property getter]

Forward range primitives.

Properties

front
Range front [@property getter]
save
auto save [@property getter]

Forward range primitives.

Parameters

keepSeparators

flag to specify if the matches should be in the resulting range

Return Value

A lazy range of strings

Examples

import std.algorithm.comparison : equal;
auto s1 = ", abc, de,  fg, hi, ";
assert(equal(splitter(s1, regex(", *")),
    ["", "abc", "de", "fg", "hi", ""]));

Split on a pattern, but keep the matches in the resulting range

import std.algorithm.comparison : equal;
import std.typecons : Yes;

auto pattern = regex(`([\.,])`);

assert("2003.04.05"
    .splitter!(Yes.keepSeparators)(pattern)
    .equal(["2003", ".", "04", ".", "05"]));

assert(",1,2,3"
    .splitter!(Yes.keepSeparators)(pattern)
    .equal([",", "1", ",", "2", ",", "3"]));

Meta