This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: UTF-8 support - char or wchar_t?


Martin Sebor <sebor@roguewave.com> writes:

> Ole Laursen wrote:

[...]

>> Thanks! What you are suggesting is to use a std::wostringstream,
>> extract a std::wstring with str(), put the data inside a std::string
>> and use an iconv wrapper to convert from the wchar_t encoding to
>> UTF-8, right?
>
> I don't think I suggested that. With iconv, unless you actually
> want wchar_t, you can just convert ordinary multibyte characters
> (say a char* encoded in ISO-8859-15 to a char* encoded in UTF-8
> or vice versa). You don't need to involve wchar_t as an intermediate
> representation as you might with codecvt (e.g., a char* in 8859 to
> UCS-4 encoded wchar_t*, and then the same wchar_t* to UTF-8 with
> another codecvt). I hope I didn't just confuse things for you :)

Well, you didn't confuse me until now. :-)

My current understanding is that I need to use a std::wostringstream
to convert numbers etc. to a string representation since they may not
be converted correctly with a std::ostringstream (e.g. in a Finnish
UTF-8 locale). But then the std::wostringstream will only give me a
std::wstring with wchar_t's. So I cast that to char's and feed it to
an iconv wrapper to get UTF-8.

Am I missing something?

Anyway, I've tried it, and it works, so once again thanks to you and
Paolo for your help!

-- 
Ole Laursen
http://www.cs.aau.dk/~olau/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]