mbrtoc8
<uchar.h>
Converts a narrow multibyte character to UTF-8 encoding.
If s is not a null pointer, inspects at most n bytes of the multibyte character string, beginning with the byte pointed to by s to determine the number of bytes necessary to complete the next multibyte character (including any shift sequences). If the function determines that the next multibyte character in s is complete and valid, converts it to UTF-8 and stores the first UTF-8 code unit in *pc8 (if pc8 is not null).
If UTF-8 encoding of the multibyte character in *s consists of more than one UTF-8 code unit, then after the first call to this function, *ps is updated in such a way that the next call to mbrtoc8
will write out the additional UTF-8 code units, without considering *s.
If s is a null pointer, the values of n and pc8 are ignored and the call is equivalent to mbrtoc8(nullptr, "", 1, ps).
If UTF-8 code unit produced is u8'0円', the conversion state *ps represents the initial shift state.
The multibyte encoding used by this function is specified by the currently active C locale.
[edit] Parameters
[edit] Return value
The first of the following that applies:
- 0 if the character converted from s (and stored in *pc8 if non-null) was the null character.
- The number of bytes
[
1,
n]
of the multibyte character successfully converted from s. - (size_t )-3 if the next UTF-8 code unit from a character whose encoding consists of multiple code units has now been written to *pc8. No bytes are processed from the input in this case.
- (size_t )-2 if the next n bytes constitute an incomplete, but so far valid, multibyte character. Nothing is written to *pc8.
- (size_t )-1 if encoding error occurs. Nothing is written to *pc8, the value EILSEQ is stored in errno and the value of *ps is unspecified.
[edit] Example
Reason: no example
[edit] References
- C23 standard (ISO/IEC 9899:2024):
- 7.30.1.1 The mbrtoc8 function