std::codecvt<InternT,ExternT,StateT>::max_length, do_max_length
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Text processing library
Regular expressions library (C++11)
Formatting library (C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++26)
Localization library
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
std::codecvt
Member functions
codecvt::max_lengthcodecvt::do_max_length
Defined in header
<locale>
(1)
public:
int max_length() const throw();
(until C++11)
int max_length() const throw();
public:
int max_length() const noexcept;
(since C++11)
int max_length() const noexcept;
(2)
protected:
virtual int do_max_length() const throw();
(until C++11)
virtual int do_max_length() const throw();
protected:
virtual int do_max_length() const noexcept;
(since C++11)
virtual int do_max_length() const noexcept;
1) Public member function, calls the member function
do_max_length
of the most derived class.2) Returns the maximum value that do_length(state, from, from_end, 1) can return for any valid range
[
from,
from_end)
and any valid state
.Contents
[edit] Return value
The maximum number of ExternT
characters that could be consumed if converted by in() to produce one InternT
character.
The non-converting specialization std::codecvt <char, char, std::mbstate_t > returns 1.
[edit] Notes
If the encoding is state-dependent (encoding() == -1), then more than max_length()
external characters may be consumed to produce one internal character.
[edit] Example
Run this code
#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 long In header-consuming codecvt_utf8, the longest multibyte character is 7 bytes long In this system's en_US.utf8, the longest multibyte character is 6 bytes long In this system's zh_CN.gb18030, the longest multibyte character is 4 bytes long
[edit] See also
MB_CUR_MAX
(macro variable)[edit]
[virtual]
ExternT
characters necessary to produce one InternT
character, if constant (virtual protected member function) [edit]