splitterASCIIAmong

Non-decoding ASCII-separator-only variant of Phobos' splitter that .

TODO generalize to separators being either chars or strings.

template splitterASCIIAmong(separators...)
splitterASCIIAmong
(
Range
)
(
return Range r
)
if (
is(typeof(Range.init[0 .. 0])) &&
is(typeof(Range.init[0]) : char)
&&
allSatisfy!(isASCII, separators)
)
if (
separators.length != 0 &&
isExpressions!separators
)

Examples

1 import std.algorithm.comparison : equal;
2 import nxt.array_help : s;
3 
4 assert(``.splitterASCIIAmong!(' ')
5          .empty);
6 
7 assert(` `.splitterASCIIAmong!(' ')
8           .empty);
9 
10 assert(`   `.splitterASCIIAmong!(' ')
11             .empty);
12 
13 assert(` - `.splitterASCIIAmong!(' ')
14             .equal([`-`].s[]));
15 
16 assert(`a`.splitterASCIIAmong!(' ')
17           .equal([`a`].s[]));
18 
19 assert(` a `.splitterASCIIAmong!(' ')
20             .equal([`a`].s[]));
21 
22 assert(` a b `.splitterASCIIAmong!(' ')
23               .equal([`a`, `b`].s[]));
24 
25 assert(` a_b `.splitterASCIIAmong!(' ')
26               .equal([`a_b`].s[]));
27 
28 assert(` - aa   bb--c-d--e`.splitterASCIIAmong!(' ', '-')
29                              .equal([`aa`, `bb`, `c`, `d`, `e`].s[]));
30 
31 assert(` - aa   bb--c-_d--_e`.splitterASCIIAmong!(' ', '-', '_')
32                              .equal([`aa`, `bb`, `c`, `d`, `e`].s[]));
33 
34 assert(` - aa ///  bb--c-_d--_e`.splitterASCIIAmong!(' ', '-', '_', '/')
35                                 .equal([`aa`, `bb`, `c`, `d`, `e`].s[]));

Meta