Christian Biesinger wrote:
Antoine wrote:

When you allocate memory with nsMemory::Alloc(), the parameter you
pass, does it represent the size of the memory in bytes or the size of
the memory in 16-bits chunks (2 bytes)?


Bytes. It is not only used for unicode strings...

PRUnichar *unicharString =
reinterpret_cast<PRUnichar*>(nsMemory::Alloc(strlen(charString) * 2) ;
// strlen * 2 because of 16 bits per character


add 1! you need space for a terminating zero.

What charset is your string in? ToNewUnicode or UTF8ToNewUnicode may be useful for you; or, if you have a filename, NS_CopyNativeToUnicode.



My original string is in ISO 8859-1 charset. I like the mbstowcs() function because there is also the opposite wcstombs() fucntion available.


I'll have a look at ToNewUnicode and UTF8ToNewUnicode to see how they manage. Do those functions have opposites too (like NewUnicodeToUTF8 or something)? A quick-search yielded nothing :-(
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to