The isValidUTF8() function

Checks if a string represents valid UTF-8 characters.

Description

The function has the following syntax:
inline bool isValidUTF8(const char* bytes, int length, int* 
charLength= NULL)

bytes specifies the string of UTF-8 characters, which cannot be null-terminated.

length specifies the number of bytes to review.

charLength is an optional argument. If you specify this argument and the bytes argument is valid, charLength is set to the number of UTF-8 characters in the bytes string. If you specify this argument and the bytes argument is not valid, charLength is set to -1.

Returns

The function returns true if length is 0 or bytes[0...length-1] is a valid UTF8 string.

Otherwise, the function returns false.

Throws

The function throws an opaque exception object if bytes is NULL or if length < 0.