std::codecvt_byname
is a std::codecvt facet which encapsulates multibyte/wide character conversion rules of a locale specified at its construction.
The standard library is guaranteed to provide the following specializations:
std::codecvt_byname<char, char, std::mbstate_t> identity conversion std::codecvt_byname<char16_t, char, std::mbstate_t>codecvt_byname
facet
codecvt_byname
facet
Constructs a new std::codecvt_byname
facet for a locale with name.
refs is used for resource management: if refs == 0, the implementation destroys the facet, when the last std::locale object holding it is destroyed. Otherwise, the object is not destroyed.
Parameters name - the name of the locale refs - the number of references that link to the facet std::codecvt_byname::~codecvt_bynameprotected:
~codecvt_byname();
Destroys the facet.
Inherited from std::codecvt Nested types Type Definitionintern_type
internT
extern_type
externT
state_type
stateT
[edit] Data members Member functions invokes do_out
std::codecvt<InternT,ExternT,StateT>
) [edit] invokes do_in
std::codecvt<InternT,ExternT,StateT>
) [edit] invokes do_unshift
std::codecvt<InternT,ExternT,StateT>
) [edit] invokes do_encoding
std::codecvt<InternT,ExternT,StateT>
) [edit] invokes do_always_noconv
std::codecvt<InternT,ExternT,StateT>
) [edit] invokes do_length
std::codecvt<InternT,ExternT,StateT>
) [edit] invokes do_max_length
std::codecvt<InternT,ExternT,StateT>
) [edit] Protected member functions converts a string from InternT
to ExternT
, such as when writing to file
std::codecvt<InternT,ExternT,StateT>
) [edit] converts a string from ExternT
to InternT
, such as when reading from file
std::codecvt<InternT,ExternT,StateT>
) [edit] generates the termination character sequence of ExternT
characters for incomplete conversion
std::codecvt<InternT,ExternT,StateT>
) [edit] returns the number of ExternT
characters necessary to produce one InternT
character, if constant
std::codecvt<InternT,ExternT,StateT>
) [edit] tests if the facet encodes an identity conversion for all valid argument values
std::codecvt<InternT,ExternT,StateT>
) [edit] calculates the length of the ExternT
string that would be consumed by conversion into given InternT
buffer
std::codecvt<InternT,ExternT,StateT>
) [edit] returns the maximum number of ExternT
characters that could be converted into a single InternT
character
std::codecvt<InternT,ExternT,StateT>
) [edit] Inherited from std::codecvt_base Nested type Definition enum result { ok, partial, error, noconv }; Unscoped enumeration type Enumeration constant Definition ok
conversion was completed with no error partial
not all source characters were converted error
encountered an invalid character noconv
no conversion required, input and output types are the same [edit] Example
This example demonstrates reading a GB18030-encoded file using the codecvt facet from a GB18030-aware locale.
#include <fstream> #include <iostream> #include <locale> #include <string> int main() { // GB18030 narrow multibyte encoding std::ofstream("text.txt") << "\x7a" // letter 'z', U+007a "\x81\x30\x89\x38" // letter 'Ã', U+00df "\xcb\xae" // CJK ideogram 'æ°´' (water), U+6c34 "\x94\x32\xbc\x35"; // musical sign 'ð' (segno), U+1d10b std::wifstream fin("text.txt"); fin.imbue(std::locale(fin.getloc(), new std::codecvt_byname<wchar_t, char, std::mbstate_t>("zh_CN.gb18030"))); for (wchar_t c; fin.get(c);) std::cout << std::hex << std::showbase << static_cast<unsigned>(c) << '\n'; }
Possible output:
[edit] Defect reportsThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 21 C++98 the standard library did not need to providestd::codecvt_byname
specializations two specializations are required [edit] See also converts between character encodings, including UTF-8, UTF-16, UTF-32
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4