nullTerminated

Returns an input range that processes directly a null terminated C string, without fully converting it to a phobos string.

nullTerminated
(
bool decode = false
C
)
(
C c
)
if (
isPointer!C &&
isSomeChar!(PointerTarget!(C))
)

Parameters

decode

When set to true the front is decoded otherwise (the default) each code point is supposed to contain 1 unit.

c
Type: C

A pointer to a character.

Return Value

Type: auto

When decoding is enabled, nullTerminated always returns a range of dchar otherwise the front type is the same as target type of the pointer passed as parameter.

Examples

1 auto text = "ab cd\0";
2 auto cString = nullTerminated(&text[0]);
3 assert(nextWord(cString) == "ab");
4 auto saved = nullTerminated(cString.save);
5 assert(nextWord(cString) == "cd");
6 assert(nextWord(saved) == "cd");
7 assert(cString.empty);
8 auto wtext = "ab cd\0"w;
9 auto cWideString = nullTerminated(&wtext[0]);
10 assert(nextWord(cWideString) == "ab"w);
11 assert(nextWord(cWideString) == "cd"w);
12 assert(cWideString.empty);

Meta