tags:

views:

230

answers:

3

I need to pass char* to XPCOM function but that function accepts PRUnichar *. How to convert from char* to PRUnichar * ?

+1  A: 

Take a look at nsAutoString.

Georg Fritzsche
Note that you only want that if you are absolutely sure your data is ASCII. To quote the doc you linked to: "assign/append/insert with _LOSSY_ conversion".
Ted Mielczarek
I think its fair to assume that other people can read.
Georg Fritzsche
I prefer to not make that assumption.
Ted Mielczarek
+1  A: 

In which character set is your char* ?

Neil
+1  A: 

If you have a UTF-8 string then you can use NS_ConvertUTF8toUTF16 or CopyUTF8toUTF16. If you have some other encoding then you'll need to use nsICharsetConverterManager or some other API to convert to something sane: http://mxr.mozilla.org/mozilla-central/source/intl/uconv/idl/nsICharsetConverterManager.idl

The XPCOM string guide has a good reference on this: https://developer.mozilla.org/En/XPCOM%3AStrings#Unicode%5FConversion%5Fns*CString_vs.nsString

Ted Mielczarek