CharRange

CharRange is an helper struct that allows to test if a char is within a full range of characters.

Constructors

this
this(S s)

Constructs the char range using a string that contains the range bounds.

this
this(C cmin, C cmax)

Constructs the char range using the two chars passed as argument.

Members

Functions

max
dchar max()

Returns the upper char in the range.

min
dchar min()

Returns the lower char in the range.

opBinaryRight
bool opBinaryRight(C c)

Returns true if a character is within the range.

toString
string toString()

Returns the range representation, as a string. This function fails if the range is not within the 0x0 .. 0x80 range.

Examples

1 auto cs1 = CharRange("ajslkdfjlz");
2 assert(cs1.min == 'a');
3 assert(cs1.max == 'z');
4 assert('b' in cs1);
5 
6 auto cs2 = CharRange('f', 'a');
7 assert(cs2.min == 'a');
8 assert(cs2.max == 'f');
9 assert('b' in cs2);
10 assert('g' !in cs2);
11 assert(cs2.toString == "abcdef", cs2.toString);
12 
13 auto cs3 = CharRange(65, 70);
14 assert(cs3.min == 65);
15 assert(cs3.max == 70);
16 assert(66 in cs3);
17 assert(71 !in cs3);

Meta