I need to pass char*
to XPCOM function but that function accepts PRUnichar *
. How to convert from char*
to PRUnichar *
?
views:
230answers:
3Note 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
2009-10-13 14:54:35
I think its fair to assume that other people can read.
Georg Fritzsche
2009-10-13 20:29:07
I prefer to not make that assumption.
Ted Mielczarek
2009-10-31 12:58:08
+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
2009-10-13 15:11:10