can i convert from char* to UChar in ICU?
I have a char * (containing utf-8 string) that i want to pass to ICU to convert it to ANSI (ISO-8859-6) . Unfortunately it seems that most ICU functions take UChar no开发者_StackOverflowt char*.
How can I make this conversion?
Did you look at the docs? UnicodeString::fromUTF8
stands out...
// given char* str
UnicodeString ustr = UnicodeString::fromUTF8(StringPiece(str));
I assume you know how to then convert ustr
to the desired codepage using UnicodeString::extract
.
You can use the static member function FromUTF8
to convert a UTF-8 StringPiece
to a UnicodeString
. So, if you have a char*, you can convert it like this:
const char* str;
size_t len;
UnicodeString ucs = UnicodeString::FromUTF8(StringPiece(str, len));
精彩评论