cf_string_decode_UTF16¶
Category: string
GitHub: cute_string.h
Decodes a single UTF16 character from the string as a UTF32 codepoint.
| Parameters | Description |
|---|---|
s |
The string. |
codepoint |
An int pointer to receive the decoded codepoint. |
Return Value¶
Returns pointer advanced past the decoded character (1 to 2 uint16_t's).
Code Example¶
Converting a UTF16 string to UTF8.
char* utf16_to_utf8(const uint16_t* text)
{
int cp;
sdyna char* s = NULL;
while (*text) {
text = cf_string_decode_UTF16(text, &cp);
cf_string_append_UTF8(s, cp);
}
return s;
}
Remarks¶
You can use this function in a loop to decode one codepoint at a time, where each codepoint represents a single UTF16 character. You can convert a UTF16 string to UTF8 by calling cf_string_append_UTF8 on another string instance inside a decode loop.