BloombergLP::bdlde::Utf8Util::advanceIfValid

Advance past valid UTF-8 code points in string.

Synopsis

Declared in <bdlde_utf8util.h>

static
IntPtr
advanceIfValid(
    int* status,
    char const** result,
    char const* string,
    IntPtr numCodePoints);

Description

Advance past 0 or more consecutive valid Unicode code points at the beginning of the specified string, until either the specified numCodePoints have been traversed, or the terminating null byte or invalid UTF-8 is encountered (whichever occurs first), and return the number of Unicode code points traversed. Set the specified *status to 0 if no invalid UTF-8 is encountered, and to a value from the ErrorStatus enum otherwise. Set the specified *result to the address of the byte immediately following the last valid code point traversed, or to string if string is empty or numCodePoints is 0. string is necessarily null-terminated, so it cannot contain embedded null bytes. The behavior is undefined unless 0 <= numCodePoints. Note that the value returned will be in the range [0 .. numCodePoints]. Also note that string may contain less than bsl::strlen(string) Unicode code points.

Return Value

number of Unicode code points traversed

Parameters

NameDescription
statusreceives 0 on success, or an ErrorStatus value
resultreceives address after the last valid code point
stringnull-terminated UTF-8 input
numCodePointsmaximum number of code points to advance