I need to pass char*
to XPCOM function but that function accepts PRUnichar *
. How to convert from char*
to PRUnichar *
?
Asked
Active
Viewed 965 times
3 Answers
3
Take a look at nsAutoString.

Georg Fritzsche
- 97,545
- 26
- 194
- 236
-
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 Oct 13 '09 at 14:54
-
2I prefer to not make that assumption. – Ted Mielczarek Oct 31 '09 at 12:58
2
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:Strings#Unicode_Conversion_nsCString_vs._nsString

Ted Mielczarek
- 3,919
- 26
- 32