Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > wchar_t -> UTF-8?

Reply
Thread Tools

wchar_t -> UTF-8?

 
 
Jon Willeke
Guest
Posts: n/a
 
      02-08-2004
This feels like a FAQ, but I've been unable to find a satisfactory
answer. Given a Unicode encoding (such as UCS-4) in wchar_t, I want to
convert to UTF-8 (or another locale-specific encoding) in a manner not
entirely unlike the following:

wstring w = L"H\xe9llo";

locale loc( "en_US.UTF-8" );
wcout.imbue( loc );
wcout << w << endl;

I've tried Visual C++ 6.0 and Borland C++ 5.6.4 on Windows, as well as
GCC 3.3.1 on Linux. They don't seem to do anything approximately like
this. I tried plugging in a hand-written codecvt subclass, but it
doesn't seem to be used.
 
Reply With Quote
 
 
 
 
John Ericson
Guest
Posts: n/a
 
      02-08-2004
"Jon Willeke" <(E-Mail Removed)> wrote in
message newsLxVb.8466$(E-Mail Removed)...
> This feels like a FAQ, but I've been unable to find a

satisfactory
> answer. Given a Unicode encoding (such as UCS-4) in

wchar_t, I want to
> convert to UTF-8 (or another locale-specific encoding) in

a manner not
> entirely unlike the following:
>
> wstring w = L"H\xe9llo";
>
> locale loc( "en_US.UTF-8" );
> wcout.imbue( loc );
> wcout << w << endl;
>
> I've tried Visual C++ 6.0 and Borland C++ 5.6.4 on

Windows, as well as
> GCC 3.3.1 on Linux. They don't seem to do anything

approximately like
> this. I tried plugging in a hand-written codecvt

subclass, but it
> doesn't seem to be used.


IIRC, Dinkumware has a library for various code conversions.
You might want to Google a bit in comp.lang.c++ and
comp.lang.c++.moderated, since there are some good threads
in there on the various issues. Be prepared for some quirks,
depending on your system. Best regards, JE


 
Reply With Quote
 
 
 
 
Tilman Kuepper
Guest
Posts: n/a
 
      02-09-2004
Hello Jon,

> [...] I tried plugging in a hand-written codecvt
> subclass, but it doesn't seem to be used.


You can find some codecvt-facets as part of the
arabica xml parser toolkit:
http://www.jezuk.co.uk/cgi-bin/view/arabica

Boost has similar facets ready for download:
http://groups.yahoo.com/group/boost/files/utf/

Plauger wrote a pair of columns in the April and
May 1999 editions of the C/C++ Users Journal. You
can find the source code on the cuj server:
http://www.cuj.com/code/

Tilman


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting from windows wchar_t to linux wchar_t yakir22@gmail.com C++ 3 08-15-2008 09:04 AM
Trying to get wchar_t... from a lookup array but type error... pls help! Julius Mong C++ 3 03-06-2004 07:27 PM
std::wstring, TCHAR, wchar_t and LPTSTR sorty C++ 4 11-25-2003 11:05 AM
string class that can convert between wchar_t and char Bren C++ 4 10-07-2003 03:24 PM
wchar_t wstring char string transformations Adrian Cornish C++ 2 07-12-2003 08:05 PM



Advertisments