How to get a string stored in Javascript in C/C++ in UTF8 format

Marc Gueury <[email protected]>
Newsgroups gmane.comp.mozilla.internationalization
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
I tried to read the string documentation and I am quite lost.

http://www.mozilla.org/projects/xpcom/string-guide.html
and mostly
http://lxr.mozilla.org/mozilla/source/xpcom/string/public/nsStringAPI.h

I have a javascript program that read HTML. Sometimes, the HTML
contains some non-ascii character. Then I call a C function with
the string.

I was using the "string" IDL type before and I was loosing non-ascii
character. But finally, my program was working fine.
My program understand UTF8 so, I tried several things :-)
But mostly this.

I have defined a IDL function like this:

   interface nsIFoo : nsISupports {
       myFunction(in AUTF8String mystring);
   };

There is a C++ function generated that got that signature

NS_IMETHOD MyFunction(const nsACString& mystring)

Then there I try to get a (char *) pointing to the data.
I tried a lot of things like wstring. But without success.

For example this
  const char * data;
  NS_CStringGetData(mystring, &data); -> core dump ?

I tried with wstring where the result was quite stranger.
For a string "abc", I got a PRUnichar * that contains
0x6261 0x0063 like it is was still in ascii or utf8 ?

Any idea or pointer to something that works
will be appreciated :-)

Thanks by advance,

Marc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.