Name

mbrlen function — Gets number of bytes in a multibyte character

Synopsis

size_t mbrlen(const char* str, size_t n, mbstate_t* ps)

The mbrlen function counts the number of bytes needed to complete the next multibyte character that str points to. At most, n bytes of str are examined.

The ps parameter points to the shift state, which keeps track of the conversion state between calls to mbrlen. If ps is a null pointer, an internal shift state is used (which is similar to calling mblen in <cstdlib>).

The return value is one of the following:

0

If the multibyte character represents the null wide character

static_cast<size_t>(-1)

If str does not point to a valid multibyte character

static_cast<size_t>(-2)

If n is too small

Anything else

If the multibyte character is valid, in which case the value returned is the number of bytes in the multibyte character

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.