| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
codecvt::max_lengthcodecvt::do_max_length |
Defined in header <locale> | ||
| (1) | ||
public: int max_length()constthrow(); | (until C++11) | |
public: int max_length()constnoexcept; | (since C++11) | |
| (2) | ||
protected: virtualint do_max_length()constthrow(); | (until C++11) | |
protected: virtualint do_max_length()constnoexcept; | (since C++11) | |
do_max_length of the most derived class.[from, from_end) and any validstate.Contents |
The maximum number ofExternT characters that could be consumed if converted byin() to produce oneInternT character.
The non-converting specializationstd::codecvt<char,char,std::mbstate_t> returns1.
If the encoding is state-dependent (encoding()==-1), then more thanmax_length() external characters may be consumed to produce one internal character.
#include <codecvt>#include <iostream>#include <locale> int main(){std::cout<<"In codecvt_utf8, the longest multibyte character is "<<std::codecvt_utf8<wchar_t>().max_length()<<" bytes long\n"; std::cout<<"In header-consuming codecvt_utf8, the longest multibyte character is "<<std::codecvt_utf8<wchar_t,0x10ffff,std::consume_header>().max_length()<<" bytes long\n"; std::cout<<"In this system's en_US.utf8, the longest multibyte character is "<<std::use_facet<std::codecvt<wchar_t,char,std::mbstate_t>>(std::locale("en_US.utf8")).max_length()<<" bytes long\n"; std::cout<<"In this system's zh_CN.gb18030, the longest multibyte character is "<<std::use_facet<std::codecvt<wchar_t,char,std::mbstate_t>>(std::locale("zh_CN.gb18030")).max_length()<<" bytes long\n";}
Output:
In codecvt_utf8, the longest multibyte character is 4 bytes longIn header-consuming codecvt_utf8, the longest multibyte character is 7 bytes longIn this system's en_US.utf8, the longest multibyte character is 6 bytes longIn this system's zh_CN.gb18030, the longest multibyte character is 4 bytes long
MB_CUR_MAX | maximum number of bytes in a multibyte character in the current C locale (macro variable)[edit] |
[virtual] | returns the number ofExternT characters necessary to produce oneInternT character, if constant(virtual protected member function)[edit] |