You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Nawal Kishore Gupta <na...@esi-india.com> on 2007/09/19 10:35:19 UTC

WCHAR to XmlCh

Dear All,

What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.

I am getting the following error:
error: no matching function for call to 
`xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'

but same thing works fine in Windows unicode and non unicode build.


Regards,

Nawal


Re: WCHAR to XmlCh

Posted by David Bertoni <db...@apache.org>.
Nawal Kishore Gupta wrote:
> Dear All,
> 
> What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.
> 
What type is WCHAR?  Do you mean wchar_t?

> I am getting the following error:
> error: no matching function for call to 
> `xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
> 
> but same thing works fine in Windows unicode and non unicode build.
That's because wchar_t on Windows is UTF-16, which is also the encoding for 
XMLCh.  However, there are not many platforms where wchar_t contains a 
UTF-16 code point.

It's very difficult to use wchar_t portably.  Instead, your application 
should use XMLCh, and use the local code page transcoder to go between 
const char* and XMLCh.  For static UTF-16 strings, you can create static 
strings using the Xerces-C constants in XMLUniDefs.hpp.  See XMLUni.hpp and 
XMLUni.cpp for examples.

Dave

Re: WCHAR to XmlCh

Posted by Wentao Deng <we...@macadamian.com>.
Go to find out what the definition of WCHAR is.
You are doing something you don't know.
If it's possible, convert to char.

Regards,
Wentao


----- Original Message ----- 
From: "Nawal Kishore Gupta" <na...@esi-india.com>
To: <c-...@xerces.apache.org>
Sent: Wednesday, September 19, 2007 10:21 AM
Subject: Re: WCHAR to XmlCh


>I think linux also has wchar with #include <wchar.h>
> 
> 
> Alberto Massari wrote:
> 
>> At 19.23 19/09/2007 +0530, Nawal Kishore Gupta wrote:
>>
>>> I am passing const WCHAR only
>>
>>
>> WCHAR is a Windows type; how do you define it on Linux?
>>
>> Alberto
>>
>>
>>> Regards,
>>>
>>> Nawal
>>>
>>> Wentao Deng wrote:
>>>
>>>> How do you call XercesDOMParser::parse?
>>>> The parameter should be const XXX *,
>>>> not const XXX *&.
>>>>
>>>> Regards,
>>>> Wentao
>>>>
>>>>
>>>> ----- Original Message ----- From: "Nawal Kishore Gupta" 
>>>> <na...@esi-india.com>
>>>> To: <c-...@xerces.apache.org>
>>>> Sent: Wednesday, September 19, 2007 4:35 AM
>>>> Subject: WCHAR to XmlCh
>>>>
>>>>
>>>>> Dear All,
>>>>>
>>>>> What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.
>>>>>
>>>>> I am getting the following error:
>>>>> error: no matching function for call to 
>>>>> `xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
>>>>>
>>>>> but same thing works fine in Windows unicode and non unicode build.
>>>>>
>>>>>
>>>>> Regards,
>>>>>
>>>>> Nawal
>>>>
>

RE: WCHAR to XmlCh

Posted by Jesse Pelton <js...@PKC.com>.
Bits is bits; storing UTF-16 into a 4-byte wchar_t string can work.  But
the unwary might make the mistake of passing a wchar_t string containing
UTF-16 with surrogate pairs to a runtime library function that expects
UTF-32.  Seems to me that all bets are off at that point.

The central point, I think, is that you have to understand the different
types and what gets stored in them to use them safely with various
libraries.  You do, and can make robust decisions based on your
understanding, but many people don't understand that functions that
process wchar_t strings expect different sequences of bytes on different
platforms.

-----Original Message-----
From: Boris Kolpackov [mailto:boris@codesynthesis.com] 
Sent: Wednesday, September 19, 2007 3:12 PM
To: c-users@xerces.apache.org
Subject: Re: WCHAR to XmlCh

Jesse Pelton <js...@PKC.com> writes:

> That assumes wchar_t holds UTF-16 (as XMLCh does).  It might not.  See
> http://www.losingfight.com/blog/2006/07/28/wchar_t-unsafe-at-any-size/
> for a wchar_t story that would be amusing if it were fiction.

What most people fail to realize is that wchar_t holds whatever you
put into it. If you want portable UTF-16 in wchar_t then put UTF-16
into it, even on platforms where wchar_t is 4-bytes long and can
hold UTF-32.

Alternatively, it is possible to use UTF-16 on platforms where
wchar_t is 2-bytes long and UTF-32 on the rest. The only parts
that will need to know about this arrangement are those that
are responsible with converting to/from wchar_t strings (e.g.,
XMLCh to/from wchar_t). If the application does not need to do
anything special with (e.g., search for) characters that are
outside the BMP (Basic Multilingual Plane), then it can use
wchar_t that contains either UTF-16 or UTF-32 without actually
caring which one it is. And I am pretty sure this is 99.9% of
applications. We use this approach in our XML data binding tool
when the user requests the underlying character type to be wchar_t.


Boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding

Re: WCHAR to XmlCh

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Jesse Pelton <js...@PKC.com> writes:

> That assumes wchar_t holds UTF-16 (as XMLCh does).  It might not.  See
> http://www.losingfight.com/blog/2006/07/28/wchar_t-unsafe-at-any-size/
> for a wchar_t story that would be amusing if it were fiction.

What most people fail to realize is that wchar_t holds whatever you
put into it. If you want portable UTF-16 in wchar_t then put UTF-16
into it, even on platforms where wchar_t is 4-bytes long and can
hold UTF-32.

Alternatively, it is possible to use UTF-16 on platforms where
wchar_t is 2-bytes long and UTF-32 on the rest. The only parts
that will need to know about this arrangement are those that
are responsible with converting to/from wchar_t strings (e.g.,
XMLCh to/from wchar_t). If the application does not need to do
anything special with (e.g., search for) characters that are
outside the BMP (Basic Multilingual Plane), then it can use
wchar_t that contains either UTF-16 or UTF-32 without actually
caring which one it is. And I am pretty sure this is 99.9% of
applications. We use this approach in our XML data binding tool
when the user requests the underlying character type to be wchar_t.


Boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding

RE: WCHAR to XmlCh

Posted by Jesse Pelton <js...@PKC.com>.
That assumes wchar_t holds UTF-16 (as XMLCh does).  It might not.  See
http://www.losingfight.com/blog/2006/07/28/wchar_t-unsafe-at-any-size/
for a wchar_t story that would be amusing if it were fiction.

-----Original Message-----
From: Keith Mendoza [mailto:pantherse@gmail.com] 
Sent: Wednesday, September 19, 2007 11:48 AM
To: c-users@xerces.apache.org
Subject: Re: WCHAR to XmlCh

Actually the C99 standard defines a wchar_t type which can be used for
wide
characters. You probably will need to typecast your wchar_t* to XMLCh*.

Keith

On 9/19/07, Nawal Kishore Gupta <na...@esi-india.com> wrote:
>
> I think linux also has wchar with #include <wchar.h>
>
>
> Alberto Massari wrote:
>
> > At 19.23 19/09/2007 +0530, Nawal Kishore Gupta wrote:
> >
> >> I am passing const WCHAR only
> >
> >
> > WCHAR is a Windows type; how do you define it on Linux?
> >
> > Alberto
> >
> >
> >> Regards,
> >>
> >> Nawal
> >>
> >> Wentao Deng wrote:
> >>
> >>> How do you call XercesDOMParser::parse?
> >>> The parameter should be const XXX *,
> >>> not const XXX *&.
> >>>
> >>> Regards,
> >>> Wentao
> >>>
> >>>
> >>> ----- Original Message ----- From: "Nawal Kishore Gupta"
> >>> <na...@esi-india.com>
> >>> To: <c-...@xerces.apache.org>
> >>> Sent: Wednesday, September 19, 2007 4:35 AM
> >>> Subject: WCHAR to XmlCh
> >>>
> >>>
> >>>> Dear All,
> >>>>
> >>>> What is the best way to covert  WCHAR to XMLCh in Linux /Unix
build.
> >>>>
> >>>> I am getting the following error:
> >>>> error: no matching function for call to
> >>>> `xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
> >>>>
> >>>> but same thing works fine in Windows unicode and non unicode
build.
> >>>>
> >>>>
> >>>> Regards,
> >>>>
> >>>> Nawal
> >>>
>
>

Re: WCHAR to XmlCh

Posted by Keith Mendoza <pa...@gmail.com>.
Actually the C99 standard defines a wchar_t type which can be used for wide
characters. You probably will need to typecast your wchar_t* to XMLCh*.

Keith

On 9/19/07, Nawal Kishore Gupta <na...@esi-india.com> wrote:
>
> I think linux also has wchar with #include <wchar.h>
>
>
> Alberto Massari wrote:
>
> > At 19.23 19/09/2007 +0530, Nawal Kishore Gupta wrote:
> >
> >> I am passing const WCHAR only
> >
> >
> > WCHAR is a Windows type; how do you define it on Linux?
> >
> > Alberto
> >
> >
> >> Regards,
> >>
> >> Nawal
> >>
> >> Wentao Deng wrote:
> >>
> >>> How do you call XercesDOMParser::parse?
> >>> The parameter should be const XXX *,
> >>> not const XXX *&.
> >>>
> >>> Regards,
> >>> Wentao
> >>>
> >>>
> >>> ----- Original Message ----- From: "Nawal Kishore Gupta"
> >>> <na...@esi-india.com>
> >>> To: <c-...@xerces.apache.org>
> >>> Sent: Wednesday, September 19, 2007 4:35 AM
> >>> Subject: WCHAR to XmlCh
> >>>
> >>>
> >>>> Dear All,
> >>>>
> >>>> What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.
> >>>>
> >>>> I am getting the following error:
> >>>> error: no matching function for call to
> >>>> `xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
> >>>>
> >>>> but same thing works fine in Windows unicode and non unicode build.
> >>>>
> >>>>
> >>>> Regards,
> >>>>
> >>>> Nawal
> >>>
>
>

Re: WCHAR to XmlCh

Posted by Nawal Kishore Gupta <na...@esi-india.com>.
I think linux also has wchar with #include <wchar.h>


Alberto Massari wrote:

> At 19.23 19/09/2007 +0530, Nawal Kishore Gupta wrote:
>
>> I am passing const WCHAR only
>
>
> WCHAR is a Windows type; how do you define it on Linux?
>
> Alberto
>
>
>> Regards,
>>
>> Nawal
>>
>> Wentao Deng wrote:
>>
>>> How do you call XercesDOMParser::parse?
>>> The parameter should be const XXX *,
>>> not const XXX *&.
>>>
>>> Regards,
>>> Wentao
>>>
>>>
>>> ----- Original Message ----- From: "Nawal Kishore Gupta" 
>>> <na...@esi-india.com>
>>> To: <c-...@xerces.apache.org>
>>> Sent: Wednesday, September 19, 2007 4:35 AM
>>> Subject: WCHAR to XmlCh
>>>
>>>
>>>> Dear All,
>>>>
>>>> What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.
>>>>
>>>> I am getting the following error:
>>>> error: no matching function for call to 
>>>> `xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
>>>>
>>>> but same thing works fine in Windows unicode and non unicode build.
>>>>
>>>>
>>>> Regards,
>>>>
>>>> Nawal
>>>


Re: WCHAR to XmlCh

Posted by Alberto Massari <am...@datadirect.com>.
At 19.23 19/09/2007 +0530, Nawal Kishore Gupta wrote:
>I am passing const WCHAR only

WCHAR is a Windows type; how do you define it on Linux?

Alberto


>Regards,
>
>Nawal
>
>Wentao Deng wrote:
>
>>How do you call XercesDOMParser::parse?
>>The parameter should be const XXX *,
>>not const XXX *&.
>>
>>Regards,
>>Wentao
>>
>>
>>----- Original Message ----- From: "Nawal Kishore Gupta" 
>><na...@esi-india.com>
>>To: <c-...@xerces.apache.org>
>>Sent: Wednesday, September 19, 2007 4:35 AM
>>Subject: WCHAR to XmlCh
>>
>>
>>>Dear All,
>>>
>>>What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.
>>>
>>>I am getting the following error:
>>>error: no matching function for call to 
>>>`xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
>>>
>>>but same thing works fine in Windows unicode and non unicode build.
>>>
>>>
>>>Regards,
>>>
>>>Nawal


Re: WCHAR to XmlCh

Posted by Nawal Kishore Gupta <na...@esi-india.com>.
I am passing const WCHAR only

Regards,

Nawal

Wentao Deng wrote:

> How do you call XercesDOMParser::parse?
> The parameter should be const XXX *,
> not const XXX *&.
>
> Regards,
> Wentao
>
>
> ----- Original Message ----- From: "Nawal Kishore Gupta" 
> <na...@esi-india.com>
> To: <c-...@xerces.apache.org>
> Sent: Wednesday, September 19, 2007 4:35 AM
> Subject: WCHAR to XmlCh
>
>
>> Dear All,
>>
>> What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.
>>
>> I am getting the following error:
>> error: no matching function for call to 
>> `xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
>>
>> but same thing works fine in Windows unicode and non unicode build.
>>
>>
>> Regards,
>>
>> Nawal
>>


Re: WCHAR to XmlCh

Posted by Wentao Deng <we...@macadamian.com>.
How do you call XercesDOMParser::parse?
The parameter should be const XXX *,
not const XXX *&.

Regards,
Wentao


----- Original Message ----- 
From: "Nawal Kishore Gupta" <na...@esi-india.com>
To: <c-...@xerces.apache.org>
Sent: Wednesday, September 19, 2007 4:35 AM
Subject: WCHAR to XmlCh


> Dear All,
> 
> What is the best way to covert  WCHAR to XMLCh in Linux /Unix build.
> 
> I am getting the following error:
> error: no matching function for call to 
> `xercesc_2_7::XercesDOMParser::parse(const WCHAR*&)'
> 
> but same thing works fine in Windows unicode and non unicode build.
> 
> 
> Regards,
> 
> Nawal
>