Re: [xml] Using wchar_t string with libxml2.



xml-bounces gnome org wrote on 26/01/2005 12:48:07:

> On Wed, Jan 26, 2005 at 12:26:09PM +0000, Arthur_Yarwood scee net wrote:
> > > You must convert your wide strings into UTF-8 strings before passing
> > them
> > > to the libxml2 API. I think
> > >     http://xmlsoft.org/encoding.html#internal
> > > is clear about that. If not I take patches to make this clearer.
> > >
> >
> > Ok, does that mean there could possibly be a loss of data, for characters
> > that need two bytes? Or have I got the wrong end of the stick when it
> > comes to storing Unicode strings?
> >
> > I've just tried using 'wcstombs()' to convert my wide string to a
> > multi-byte string, which I can then BAD_CAST to xmlChar. Is this the
> > correct way of doing this? I just tried passing a random arabic string
> > through wcstombs() and it fails, because it cannot a wide character.
>
>   You need to find the way to convert your input. UTF-8 can handlle the
> full Unicode range.
>
I thought this is what iconv was supposed to do. I'm using it like this:-

   xmlChar *out = new xmlChar[2048];
   iconv_t cd = iconv_open("UTF-8", "UTF-16");
   TRACE(_T("errno: %d"), errno);
   ASSERT( cd != (iconv_t)-1 );

size_t inbytesleft = wcslen(in) * sizeof(wchar_t), outbytesleft = 2048 * sizeof(xmlChar); size_t result = iconv(cd, (const char**)&in, &inbytesleft, (char**)&out, &outbytesleft);
   TRACE(_T("errno: %d"), errno);

   iconv_close(cd);

Am I just mis-using it somehow? I'm guessing I've got the wrong code for the input. Any ideas?

> > How should I convert my random arabic string to utf-8? Is it possible?
>
>   Any Unicode code point has a representation in UTF-8, the answer should
> be yes.
>
That's cool.

> > **********************************************************************
> > This email and any files transmitted with it are confidential and
> > intended solely for the use of the individual or entity to whom they
> > are addressed. If you have received this email in error please notify
> > postmaster scee net
>
>   This is not compatible with the mailing-list policy. Please get rid of
> this footer because we will make any communication made to this list publicly
> available and searchable even by non-subscribers to the list. Tell your
> management and IT hierarchy that this is incompatible with working with
> Open Source projects ! You may get private support for libxml2 code but
> I exect this to be only made as part of commercial support contacts (with
> whoever may want to sell such support).
>

Ahh, yeah I forgot that they append that. I do apologise, I'll use my own personal email account from now on.

Arthur.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]