banli wrote:
say if I have a variable nsStr of type of nsEmbedString, could anyone tell
me how to convert the return value of nsStr.get() to char*? And how to
output the return value of nsStr.get() to file?

I tried to output the return value to file using fputws(nsStr.get(), fd).
But the compiler complains with "cannot convert" 'const PRUnichar*' to
'const wchar_t*'.

Unfortunately, there is not a way to to UTF16->UTF8 conversions without linking to non-frozen stuff (yet). Darin and I are trying to figure out the minimum necessary linkage to accomplish these kinds of tasks.


You can't cast PRUnichar* to wchar_t* because on most *ixes, wchar_t is a four-byte type. However, you can safely do a funky copy-conversion to a wchar_t type:

PRUnichar *start = nsStr.get();
PRUnichar *end nsStr.get() + nsStr.Length();
wchar_t *wstart = new wchar_t[nsStr.Length()];
wchar_t *wend = start + nsStr.Length();

for(; start < end; ++start) {
  *wstart = (wchar_t) *start;
  ++wstart;
}
*wstart = 0;

There are also some interfaces in intl (charset conversion) that might do the trick for you.

--BDS
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to