chsvlib
chsv helper source code

◆ u8toucp_s()

errno_t Chusov::String::u8toucp_s ( int *restrict  pStatus,
ucp_t *restrict  pUcp,
const char *restrict  pUtf,
rsize_t  cbUtf 
)
noexcept

Securely converts one multibyte UTF-8 code to a Unicode 11.0 code point.

Parameters
[in]pStatusreceives a status of the conversion. If the conversion succeeds, pStatus receives the number of bytes occupied by the UTF-8 character pointed to by pUtf. If pUtf points to an invalid UTF-8 code, the pStatus parameter receives -1, and the function returns the EILSEQ code. If a runtime constraint is violated by the call, the value of pStatus is not changed.
[out]pUcpis an optional pointer to a buffer to receive the scalar Unicode code point which corresponds to a code specified by pUtf.
[in]pUtfis a pointer to a UTF-8 code to be converted to a Unicode code point.
[in]cbUtfspecifies the maximal number of bytes to read from pUtf.
Returns
The function returns zero if successful or an appropriate non-zero errno code, if there is a runtime-constraint violation, or pUtf does not point to a valid multibyte character.

The function implements the conversion of a UTF-8 encoded character to the corresponding Unicode 11.0 code point in a portable way and independently of the current locale.

It is a secure variant of the u8toucp function. Unlike other encoding conversion functions of chsvlib, ucptou8_s does not have a standardized analogue and is introduced to verify that pUtf is not NULL and cbUtf is not greater than RSIZE_MAX. Additionally, unlike ucptou8, the function verifies that the code point appertains to the set of valid codes defined for UTF-8 by the Unicode 11.0 standard.

See also
ucptou8_s;
ucpstou8s_s;
u8toucp.