to upper with char16_t array
Is there any way to do it nicely. When I try to use Boost's to_upper()
, I get a std::bad_cast
, so I ended with something like this:
while(str[i]!=u'\0')
{
str[i]=(char16_t)to_upper((wchar_t)str[i]);
i++;
}
I'm not even sure that this is correct because I don't know if it is guaranteed that to_upper
of char16_t
has the same size as the original character. And I'm not sure if that would cause overwriting of the next character or reading again the second half of the last one precessed. Sorry for my 开发者_开发问答stupid questions, but I have problems when it comes to random access and char types that have variable-length encodings.
The best way to do it is probably something like this:
char16_t upper = std::use_facet<std::ctype<char16_t>>(std::locale()).toupper(ch);
精彩评论