std::mbrtoc8(3)
β¨ NAME β¨
std::mbrtoc8 β std::mbrtoc8. Thatβs literally the name, bestie π
. This is the std::mbrtoc8(3) page from the C++ Standard Library, and itβs here to help you convert a narrow multibyte character into UTF-8. Slay.
πΈ Synopsis πΈ
Defined in header <cuchar>
std::size_t mbrtoc8( char8_t* pc8,
const char* s, (since C++20)
std::size_t n,
std::mbstate_t* ps );
Converts a narrow multibyte character to UTF-8 encoding. Periodt. π¦
If s is not a null pointer, it 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, it converts it to UTF-8 and stores the first UTF-8 code unit in *pc8 (if pc8 is not null). No cap. β¨
If the 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. Itβs giving βI remember where we were, donβt worry.β π«Ά
If s is a null pointer, the values of n and pc8 are ignored and the call is equivalent to std::mbrtoc8(nullptr, "", 1, ps). Iconic shortcut behavior. π
If the UTF-8 code unit produced is u8'\0', the conversion state *ps represents the initial shift state. Reset era. π
The multibyte encoding used by this function is specified by the currently active C locale. So yeah, locale girlies, this oneβs for you. π
π«Ά Parameters π«Ά
pc8β pointer to the location where the resulting UTF-8 code units will be written. πsβ pointer to the multibyte character string used as input. π¦nβ limit on the number of bytes insthat can be examined. β¨psβ pointer to the conversion state object used when interpreting the multibyte string. π
π₯ Return value π₯
The first of the following that applies, bestie:
0if the character converted froms(and stored in*pc8if non-null) was the null character. π«Ά- the number of bytes
[1...n]of the multibyte character successfully converted froms. π static_cast<std::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. πstatic_cast<std::size_t>(-2)if the nextnbytes constitute an incomplete, but so far valid, multibyte character. Nothing is written to*pc8. πstatic_cast<std::size_t>(-1)if encoding error occurs. Nothing is written to*pc8, the valueEILSEQis stored inerrnoand the value of*psis unspecified. π
π§ Example π§
This section is incomplete Reason: no example
Not me showing up with no example π. Itβs fine. We move. π¦
π See also π
c8rtombβ converts UTF-8 string to narrow multibyte encoding(C++20)(function). π₯- C documentation for
mbrtoc8. π
π Category π
Todo no exampleπ
mwah β thatβs the whole vibe, sourced from http://cppreference.com, dated 2024.06.10, and itβs the std::mbrtoc8(3) page. ππβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms