As the question says:
typedef __CHAR16_TYPE__ char16_t;
int main(void)
{
static char16_t test[] = u"Hello World!\n";
printf("Length = %d", strlen(test)); // strlen equivalent for char16_t ???
return 0;
}
I searched and found only C++ solutions.
My compiler is GCC 4.7.
Edit:
To clarify, I was searching for a solution that returns the count of code points, not the count of characters.
These two are quite different for UTF-16 strings containing characters outside the BMP.
Here’s your basic strlen:
Here’s a more efficient and popular strlen:
Hope this helps.
Warning: This doesn’t work properly when counting the characters (not code points) of a UTF-16 string. This is especially true when
__STDC_UTF_16__is defined to1.UTF-16 is variable length (2 bytes per character in the BMP or 4 bytes per character outside the BMP) and that is not covered by these functions.