public member function
<locale>
std::codecvt::lengthint length (state_type& state, const extern_type* from, const extern_type* from_end, size_t max) const;
Return length of translated sequence
Returns the number of external characters in the range [from,from_end) that could be translated into at maximum of max internal characters, as if applying codecvt::in.state is also updated as if codecvt::in was called for a buffer of max internal characters.
Internally, this function simply calls the virtual protected member do_length, which behaves as described above by default.
[from,from_end)
, which contains all the characters between from and from_end, including the character pointed by from but not the character pointed by from_end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// codecvt::length example
#include <iostream> // std::wcout, std::endl
#include <locale> // std::locale, std::codecvt, std::use_facet
#include <cwchar> // std::mbstate_t
#include <cstddef> // std::size_t
int main ()
{
typedef std::codecvt<wchar_t,char,std::mbstate_t> facet_type;
std::locale loc;
const facet_type& myfacet = std::use_facet<facet_type>(loc);
const char source[] = "abcdefghijklmnopqrstuvwxyz";
// prepare objects for codecvt::length:
std::mbstate_t mystate;
const char * pc;
wchar_t * pwc;
// calculate length of dest (max 30):
std::size_t length = myfacet.length (mystate, source, source+sizeof(source), 30);
wchar_t* dest = new wchar_t[length];
myfacet.in (mystate, source, source+sizeof(source), pc, dest, dest+length, pwc);
std::wcout << dest << std::endl;
delete[] dest;
return 0;
}
abcdefghijklmnopqrstuvwxyz
[from,from_end)
are accessed.
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