std::codecv...do_encoding(3)
π NAME π
std::codecvt::encoding,do_encoding β std::codecvt::encoding,do_encoding
Okay bestie, welcome to std::codecv...do_encoding(3) from the C++ Standard Libary manual β and yes, that's βLibaryβ exactly how the header spells it, I don't make the rules ππ
. This page is all about the member that tells you how a codecvt facet handles character counts, and it is lowkey iconic.
β¨ Synopsis β¨
Defined in header <locale>
public: (until C++11)
int encoding() const throw();
public: (since C++11)
int encoding() const noexcept; (1)
protected:
(until C++11)
virtual int do_encoding() const throw(); (2)
protected:
(since C++11)
virtual int do_encoding() const noexcept;
- This is the public member function, and it calls the member function
do_encodingof the most derived class. - This is the protected virtual one. If the encoding represented by this
codecvtfacet maps each internal character to the same, constant number of external characters, it returns that number. If the encoding is variable-length (e.g.UTF-8orUTF-16), it returns0. If the encoding is state-dependent, it returns-1.
Heads-up, bestie: those return values are the whole vibe check here β constant count,0for variable,-1for state-dependent. Periodt.
π Return value π
- The exact number of
externTcharacters that correspond to oneinternTcharacter, if constant. 0if the number varies.-1if the encoding is state-dependent.
The non-converting specialization std::codecvt<char, char, std::mbstate_t> returns 1. Slay.
π Example π
The manpage says // Run this code β so go off:
#include <iostream>
#include <locale>
int main()
{
std::cout << "en_US.utf8 is a variable-length encoding, encoding() returns "
<< std::use_facet<std::codecvt<wchar_t, char,
std::mbstate_t>>(
std::locale("en_US.utf8")
).encoding() << '\n';
std::cout << "zh_CN.gb18030 is also variable-length, encoding() == "
<< std::use_facet<std::codecvt<wchar_t, char,
std::mbstate_t>>(
std::locale("zh_CN.gb18030")
).encoding() << '\n';
std::cout << "ru_RU.koi8r is a single-byte encoding, encoding() == "
<< std::use_facet<std::codecvt<wchar_t, char,
std::mbstate_t>>(
std::locale("ru_RU.koi8r")
).encoding() << '\n';
}
π¦ Output π¦
en_US.utf8 is a variable-length encoding, encoding() returns 0
zh_CN.gb18030 is also variable-length, encoding() == 0
ru_RU.koi8r is a single-byte encoding, encoding() == 1
π See also π
MB_CUR_MAXβ maximum number of bytes in a multibyte character in the current C locale (macro variable).do_max_length[virtual]β returns the maximum number ofExternTcharacters that could be converted into a singleInternTcharacter (virtual protected member function).
Source/version/date cuties: http://cppreference.com, 2024.06.10, and the page tag std::codecv...do_encoding(3) β mwah, that's the whole 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