You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by qchen <qc...@micron.com> on 2003/03/04 16:43:17 UTC

wchar_t and XMLCh

I know this question has probably been discussed before, but I just want to see if there are any new solutions. 
 
Basically I need to convert the XMLCh* to a std::wstring and vice versa. In Xerces, XMLCh is typdef-ed to unsigned short (2 bytes). Under win32, there is no need for conversion since wchar_t is also typedef-ed to unsigned short. In Solaris/Linux/VMS, however, wchar_t is typedef-ed to unsigned long (4 bytes), so the conversion seem to be inevitable.
 
My question is: Does Xerces implementation requires that the size XMLCh to be 2 bytes?  if I change the typedef of XMLCh to wchar_t and recompile the xerces, would it work? I know the answer is probably no, but I just want to make sure. Of course the memory usage will be doubled if we change the XMLCh to 4 bytes, but that is not a concern for me.
 
If the conversion is inevitable, does xerces provide some helper classes/functions to do that?
 
Any suggestions are greatly appreciated.
 
 
 
Qi Chen
Micron Tech.
 
 

Re: wchar_t and XMLCh

Posted by Triger Konstantin <ko...@mainsoft.com>.
I changed, and it works for me. However I use SAX only.

-Kosta
  ----- Original Message ----- 
  From: qchen 
  To: xerces-c-dev@xml.apache.org 
  Sent: Tuesday, March 04, 2003 5:43 PM
  Subject: wchar_t and XMLCh


  I know this question has probably been discussed before, but I just want to see if there are any new solutions. 

  Basically I need to convert the XMLCh* to a std::wstring and vice versa. In Xerces, XMLCh is typdef-ed to unsigned short (2 bytes). Under win32, there is no need for conversion since wchar_t is also typedef-ed to unsigned short. In Solaris/Linux/VMS, however, wchar_t is typedef-ed to unsigned long (4 bytes), so the conversion seem to be inevitable.

  My question is: Does Xerces implementation requires that the size XMLCh to be 2 bytes?  if I change the typedef of XMLCh to wchar_t and recompile the xerces, would it work? I know the answer is probably no, but I just want to make sure. Of course the memory usage will be doubled if we change the XMLCh to 4 bytes, but that is not a concern for me.

  If the conversion is inevitable, does xerces provide some helper classes/functions to do that?

  Any suggestions are greatly appreciated.



  Qi Chen
  Micron Tech.


Re: wchar_t and XMLCh

Posted by David N Bertoni/Cambridge/IBM <da...@us.ibm.com>.



> Basically I need to convert the XMLCh* to a std::wstring and vice versa.
In Xerces, XMLCh is
> typdef-ed to unsigned short (2 bytes). Under win32, there is no need for
conversion since wchar_t
> is also typedef-ed to unsigned short. In Solaris/Linux/VMS, however,
wchar_t is typedef-ed to
> unsigned long (4 bytes), so the conversion seem to be inevitable.

There are several reason there's no need for conversion on Win32. One is
that Visual C++ 6.0 doesn't not implement wchar_t as a proper type, which
is not correct.  Most of the platforms to which you refer, depending on the
age of the compiler, _do_ implement wchar_t as a proper type, and not as a
typedef.  The other, and more important reason, is because Win32 uses
Unicode, so wide characters are known to be UCS-2/UTF-16 code points.

> My question is: Does Xerces implementation requires that the size XMLCh
to be 2 bytes?  if I
> change the typedef of XMLCh to wchar_t and recompile the xerces, would it
work? I know the
> answer is probably no, but I just want to make sure. Of course the memory
usage will be doubled
> if we change the XMLCh to 4 bytes, but that is not a concern for me.

For any given operating system, the issue is not really the size of XMLCh,
it's whether the operating system assumes wide characters are UCS-2/UTF-16
code points.  If not, there's no point in making XMLCh and wchar_t
compatible, because the OS cannot process them.

You should re-examine why you're storing UTF-16 encoded character, like
Xerces produces, in std::wstring.  std::basic_string<XMLCh> might be a
better choice.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org