Handle UTF-8 sequence.
More...
Handle UTF-8 sequence.
- Note
- This module was introduced by release 2.1.0.
◆ sombok_decode_utf8()
unistr_t* sombok_decode_utf8 |
( |
unistr_t * |
unistr, |
|
|
size_t |
maxchars, |
|
|
const char * |
utf8, |
|
|
size_t |
utf8len, |
|
|
int |
check |
|
) |
| |
Decode UTF-8 string to Unicode string
- Parameters
-
[out] | unistr | Unicode string, must not be NULL. |
[in] | maxchars | maximum number of characters to be decoded. 0 means infinite |
[in] | utf8 | source UTF-8 string |
[in] | utf8len | length of string |
[in] | check | 0: no check; 1: check malformed sequence; 2: check surrogate too; 3: check codes beyond Unicode too |
- Returns
- Unicode string. If unistr->str was NULL or maxchars was 0 (infinite), required buffer will be (re-)allocated. If error occurred, NULL is returned and errno is set.
- Note
- unistr->str must not point to static memory.
◆ sombok_encode_utf8()
char* sombok_encode_utf8 |
( |
char * |
utf8, |
|
|
size_t * |
utf8lenp, |
|
|
size_t |
maxbytes, |
|
|
unistr_t * |
unistr |
|
) |
| |
Encode Unicode string to UTF-8 string
- Parameters
-
[out] | utf8 | string buffer, may be NULL. |
[out] | utf8lenp | pointer to length of buffer, may be NULL. |
[in] | maxbytes | maximum number of bytes to be encoded. 0 means infinite |
[in] | unistr | source Unicode string, must not be NULL. |
- Returns
- string buffer. If utf8 was NULL or maxbytes was 0 (infinite), required buffer will be (re-)allocated. If error occurred, NULL is returned and errno is set.
- Note
- utf8 must not point to static memory.