chsvlib
chsv helper source code

◆ ucpstou8s()

std:: size_t Chusov::String::ucpstou8s ( char *restrict  pUtf,
const ucp_t *restrict  pUcp,
std::size_t  cbUtf 
)
noexcept

Converts a sequence of Unicode 11.0 code points to a sequence of UTF-8 multibyte characters, and writes these characters into a buffer.

Parameters
[out]pUtfis a pointer to an output buffer receiving at most cbUtf bytes of the UTF-8 sequence of multibyte characters. No more than cbUtf bytes of the buffer are modified.
[in]pUcpis an array of Unicode 11.0 code points for the function to represent in the UTF-8 format. The function reads elements of the array until cbUtf bytes has been written to the pUtf buffer or a null character has been read from pUcp and written to pUtf.
[in]cbUtfis a maximum number of bytes to be written to the pUtf buffer. No more than that number of bytes will be modified.
Returns
If a code point in pUcp cannot be represented with a valid UTF-8 character, the function returns (size_t)(-1) (note however that validity of the codes is not guaranteed by a successful return value of the function). Otherwise, the function returns the number of bytes modified, not including a terminating null character, if any. The output string pointed to by pUcp will be null-terminated unless the returned value equals cbUtf.

The function is built in a portable way to perform the conversion independently of the current locale. The interface of the function is otherwise similar to one of the wcstombs function defined by the C standard.

A successful execution of the function does not guarantee that all UTF-8 codes of the output string or the scalars of the input string are in a valid state as defined by the Unicode 11.0 standard. However, this verification is performed by the bound-checking alternative ucpstou8s_s.

See also
ucpstou8s_s;
u8stoucps;
ucptou8.