Firstly, std :: wstring is an instance of std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > .
Although most of the real work is done by char_traits, and everyone can write their own, this is done primarily to use the C runtime library with different character sizes.
The method of analysis is in the * element pointer until the symbol character indicated by char_traits is reached.
However, you can build with a pointer and a length, in which case it will read the number of characters that it tells you, and will contain any null bytes. You can have inline null bytes in basic_string, and if you call length () or size (), which are aliases for the same thing, it will tell you how many characters it contains.
There is no magic in char_traits to decode multi-element characters as one, and you should not try to implement it that way.
Cashcow
source share