开发者

can i convert from char* to UChar in ICU?

开发者 https://www.devze.com 2023-03-05 09:02 出处:网络
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*.

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

精彩评论

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

关注公众号