|
NAMEmbrlen —
get number of bytes in a character (restartable)
LIBRARYStandard C Library (libc, -lc)SYNOPSIS#include <wchar.h>
size_t
DESCRIPTIONThembrlen () function inspects at most
n bytes pointed to by s to
determine the number of bytes needed to complete the next multibyte character.
The mbstate_t argument,
ps, is used to keep track of the shift state. If it is
It is equivalent to: mbrtowc(NULL, s, n, ps); Except that when ps is a
RETURN VALUESThembrlen () functions returns:
EXAMPLESA function that calculates the number of characters in a multibyte character string:size_t nchars(const char *s) { size_t charlen, chars; mbstate_t mbs; chars = 0; memset(&mbs, 0, sizeof(mbs)); while ((charlen = mbrlen(s, MB_CUR_MAX, &mbs)) != 0 && charlen != (size_t)-1 && charlen != (size_t)-2) { s += charlen; chars++; } return (chars); } ERRORSThembrlen () function will fail if:
SEE ALSOmblen(3), mbrtowc(3), multibyte(3)STANDARDSThembrlen () function conforms to
ISO/IEC 9899:1999 (“ISO C99”).
Visit the GSP FreeBSD Man Page Interface. |