std::codecvt<InternT,ExternT,State>::length,do_length (3) - Linux Manuals
std::codecvt<InternT,ExternT,State>::length,do_length: std::codecvt<InternT,ExternT,State>::length,do_length
Command to display std::codecvt<InternT,ExternT,State>::length,do_length
manual in Linux: $ man 3 std::codecvt<InternT,ExternT,State>::length,do_length
NAME
std::codecvt<InternT,ExternT,State>::length,do_length - std::codecvt<InternT,ExternT,State>::length,do_length
Synopsis
Defined in header <locale>
public:
int length( StateT& state,
const ExternT* from, (1)
const ExternT* from_end,
std::size_t max ) const;
protected:
virtual int do_length( StateT& state,
const ExternT* from, (2)
const ExternT* from_end,
std::size_t max ) const;
1) public member function, calls the member function do_length of the most derived class.
2) attempts to convert the externT characters from the character array defined by [from, from_end), given initial conversion state state, to at most max internT characters, and returns the number of externT characters that such conversion would consume. Modifies state as if by executing do_in(state, from, from_end, from, to, to+max, to) for some imaginary [to, to+max) output buffer.
Return value
The number of externT characters that would be consumed if converted by do_in() until either all from_end-from characters were consumed or max internT characters were produced, or a conversion error occurred.
The non-converting specialization std::codecvt<char, char, std::mbstate_t> returns std::min(max, from_end-from)
Example
// Run this code
#include <locale>
#include <string>
#include <iostream>
int main()
{
// narrow multibyte encoding
std::string s = "z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
std::mbstate_t mb = std::mbstate_t();
std::cout << "Only the first " <<
std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
std::locale("en_US.utf8")
).length(mb, &s[0], &s[s.size()], 2)
<< " bytes out of " << s.size() << " would be consumed "
" to produce the first 2 characters\n";
}
Output:
Only the first 3 bytes out of 10 would be consumed to produce the first 2 characters
See also
do_in converts a string from externT to internT, such as when reading from file
(virtual protected member function)
[virtual]
Pages related to std::codecvt<InternT,ExternT,State>::length,do_length
- std::codecvt<InternT,ExternT,State>::always_noconv,do_always_noconv (3) - std::codecvt<InternT,ExternT,State>::always_noconv,do_always_noconv
- std::codecvt<InternT,ExternT,State>::codecvt (3) - std::codecvt<InternT,ExternT,State>::codecvt
- std::codecvt<InternT,ExternT,State>::encoding,do_encoding (3) - std::codecvt<InternT,ExternT,State>::encoding,do_encoding
- std::codecvt<InternT,ExternT,State>::in,std::codecvt<InternT,ExternT,State>::do_in (3) - std::codecvt<InternT,ExternT,State>::in,std::codecvt<InternT,ExternT,State>::do_in
- std::codecvt<InternT,ExternT,State>::max_length,do_max_length (3) - std::codecvt<InternT,ExternT,State>::max_length,do_max_length
- std::codecvt<InternT,ExternT,State>::out,do_out (3) - std::codecvt<InternT,ExternT,State>::out,do_out
- std::codecvt<InternT,ExternT,State>::unshift,do_unshift (3) - std::codecvt<InternT,ExternT,State>::unshift,do_unshift
- std::codecvt<InternT,ExternT,State>::~codecvt (3) - std::codecvt<InternT,ExternT,State>::~codecvt
- std::codecvt (3) - std::codecvt
- std::codecvt_base (3) - std::codecvt_base
- std::codecvt_byname (3) - std::codecvt_byname
- std::codecvt_mode (3) - std::codecvt_mode
- std::codecvt_utf8 (3) - std::codecvt_utf8
- std::codecvt_utf8_utf16 (3) - std::codecvt_utf8_utf16
- std::codecvt_utf16 (3) - std::codecvt_utf16
- std::collate (3) - std::collate