ffutf
Utility functions for manipulating Unicode Transformation Format (UTF) compatible data
Functions
Unicode-aware string length functions

Functions

size_t strlen_u (const char *s, int type)
 Length of a unicode string. More...
 
size_t strnlen_u (const char *s, size_t max_len, int type)
 Length of a unicode string with a length limit. More...
 

Detailed Description

Note
If an invalid FILE pointer is specified, the resulting behaviour can be specified by specifying the FFUTF_FAILSAFELY macro definition in compile-time. If the aforementioned macro is specified, a NULL FILE pointer will cause the program to abort. Otherwise, a segmentation fault is induced. Any expansion associated with the macro will be ignored.
If an invalid type is specified, the format is assumed to be ASCII.
It is the caller's responsibility to issue a string pointer that agrees with the specified type. For example, if a one-byte array is specified for a UTF32 type, the program may crash due to a segmentation fault as four bytes are in fact needed.
Emoji modifier sequences and Zero Width Joiner (ZWJ) sequences are not supported. This means that such sequences will be read as individual Unicode characters. For example, the rainbow flag which is formed with four Unicode characters (white flag, variation selector, ZWJ, rainbow) will be read as a length of four no matter the encoding.

Function Documentation

◆ strlen_u()

size_t strlen_u ( const char *  s,
int  type 
)

Length of a unicode string.

Parameters
sA valid string pointer.
typeA valid type.
Returns
The length of the string in terms of Unicode characters. If 0 is returned, the length of the string may be in fact 0, or there is a non-standard error where ffutf_errno is set to a non-zero value.

◆ strnlen_u()

size_t strnlen_u ( const char *  s,
size_t  max_len,
int  type 
)

Length of a unicode string with a length limit.

Parameters
sA valid string pointer.
max_lenThe maximum length that can be parsed in terms of Unicode characters.
typeA valid type.
Returns
The length of the string in terms of Unicode characters. If 0 is returned, the length of the string may be in fact 0, or there is a non-standard error where ffutf_errno is set to a non-zero value.