开发者

Convert ICU UnicodeString to platform dependent char * (or std::string)

开发者 https://www.devze.com 2023-01-30 01:17 出处:网络
In my application I use ICU UnicodeString to store my strings. Since I use some libraries incompatible with ICU, I need to convert UnicodeString to its platform dependent representation.

In my application I use ICU UnicodeString to store my strings. Since I use some libraries incompatible with ICU, I need to convert UnicodeString to its platform dependent representation.

Basicly what I need to do is reverse process form creating new UnicodeString object - new UnicodeString("string encoded in system locale").

I found out this topic - so I know it can be done with use of stringstream.

So my answer is, can it be done in some other simpler way, with开发者_JAVA技巧out using stringstream to convert?


i use

std::string converted;
us.toUTF8String(converted);

us is (ICU) UnicodeString


You could use UnicodeString::extract() with a codepage (or a converter). Actually passing NULL for the codepage will use what ICU detected as the default codepage.


You could use the functions in ucnv.h -- namely void ucnv_fromUnicode (UConverter *converter, char **target, const char *targetLimit, const UChar **source, const UChar *sourceLimit, int32_t *offsets, UBool flush, UErrorCode *err). It's not a nice C++ API like UnicodeString, but it will work.

I'd recommend just sticking with the operator<< you're already using if at all possible. It's the standard way to handle lexical conversions (i.e. string to/from integers) in C++ in any case.

0

精彩评论

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