开发者

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜