CharSwitch

The CharSwitch structure allows to define static sets of character.

Unlike CharMap it's more adapted to sets made of unicode characters because the characters are tested with a switch table that's generated at compile-time rather than reading, with an indirection, a sparse array of booleans.

The structure uniquely implements the in operator.

struct CharSwitch (
A...
) if (
A.length
) {}

Examples

1 // syntax example for a character range
2 alias digits = static immutable CharSwitch!("[0..9]") ;
3 assert('0' in digits);
4 assert('e' !in digits);
5 
6 // many ranges are accepted
7 alias hexdgs = static immutable CharSwitch!("[0..9]", "[A..F]", "[a..f]");
8 assert('0' in hexdgs);
9 assert('e' in hexdgs);
10 assert('f' in hexdgs);
11 assert('G' !in hexdgs);
12 
13 // ranges and chars can be mixed
14 alias frenchchars = static immutable CharSwitch!('à','é','è','ç',"[a..z]","[A..Z]",'ù');
15 assert('ß' !in frenchchars);
16 assert('é' in frenchchars);

Meta