Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Thu, 03 Jul 2008 11:13:00 -0400,    group: microsoft.public.win32.programmer.international        back       


Converting UTF16 characters to their UTF8 representation   
I need to encrypt an array of UTF16 characters and eventually decrypt 
back to the UTF16 array. To do this I need to convert the UTF16 array to 
an array of UTF8 characters, but in such a way that each UTF16 character 
becomes equivalent to the two characters which comprises the UTF16 
character. When I decrypt back I need to take my array of UTF8 
characters and convert it to the equivalent array of UTF16 characters.

How do I do that using the Win32 API ?

I do not think the WideCharToMultiByte/MultiByteToWideChar will work 
properly, as I believe they do conversions rather than equivalents.
date: Thu, 03 Jul 2008 11:13:00 -0400   author:   Edward Diener

Re: Converting UTF16 characters to their UTF8 representation   
Edward Diener wrote:
> I need to encrypt an array of UTF16 characters and eventually decrypt 
> back to the UTF16 array. To do this I need to convert the UTF16 array to 
> an array of UTF8 characters, but in such a way that each UTF16 character 
> becomes equivalent to the two characters which comprises the UTF16 
> character. When I decrypt back I need to take my array of UTF8 
> characters and convert it to the equivalent array of UTF16 characters.
> 
> How do I do that using the Win32 API ?
> 
> I do not think the WideCharToMultiByte/MultiByteToWideChar will work 
> properly, as I believe they do conversions rather than equivalents.

I realized I can use the LOBYTE, HIBYTE, and MAKEWORD macros to achieve 
what I want.
date: Thu, 03 Jul 2008 11:33:07 -0400   author:   Edward Diener

Re: Converting UTF16 characters to their UTF8 representation   
> To do this I need to convert the UTF16 array to 
> an array of UTF8 characters, but in such a way that each UTF16 character 
> becomes equivalent to the two characters which comprises the UTF16 
> character.

UTF-8 uses between 1 and 4 bytes, not 2.
How can a character be equivalent to two characters?


> I do not think the WideCharToMultiByte/MultiByteToWideChar will work 
> properly, as I believe they do conversions rather than equivalents.

I don't understand what you mean by "equivalents"
WideCharToMultiByte/MultiByteToWideChar will do conversion,
that is valid and will give you UTF-8.
If you want something else, the result is not UTF-8 anymore.


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Thu, 03 Jul 2008 21:27:24 -0700   author:   Mihai N.

Re: Converting UTF16 characters to their UTF8 representation   
> I realized I can use the LOBYTE, HIBYTE, and MAKEWORD macros to achieve 
> what I want.
That has absolutely nothing to do with UTF-8
And for what you want you don't need any macros, just cast the pointer
to WCHAR to a pointer to BYTE.


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Thu, 03 Jul 2008 21:28:31 -0700   author:   Mihai N.

Re: Converting UTF16 characters to their UTF8 representation   
Edward Diener  writes:

> To do this I need to convert the UTF16 array to an array of
> UTF8 characters, but in such a way that each UTF16 character
> becomes equivalent to the two characters which comprises the
> UTF16 character.

That encoding is called CESU-8.
date: Fri, 04 Jul 2008 11:28:47 +0300   author:   Kalle Olavi Niemitalo

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us