findNullTerminated

Looks for \0 in the haystack and returns the part of the haystack ahead of it.

Returns $(D_KEYWORD null) if haystack doesn't contain a null character.

@nogc nothrow pure @trusted
inout(char[])
findNullTerminated
(
return inout char[] haystack
)

Parameters

haystack char[]

Memory block.

Return Value

Type: inout(char[])

The subrange that spans all bytes before the null character or $(D_KEYWORD null) if the haystack doesn't contain any.

Examples

t
{
    assert(equal(findNullTerminated("abcdef\0gh"), "abcdef"));
    assert(equal(findNullTerminated("\0garbage"), ""));
    assert(equal(findNullTerminated("\0"), ""));
    assert(equal(findNullTerminated("cstring\0"), "cstring"));
    assert(findNullTerminated(null) is null);
    assert(findNullTerminated("abcdef") is null

Meta