This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: UTF-8 support - char or wchar_t?
Hi,
Paolo Carlini <pcarlini@suse.de> writes:
> Carlo Wood wrote:
>
>>Can you please explain why one needs wchar_t (wcout)
>>at all when using UTF-8? I'd expect that UTF-8 fits
>>in a stream of 8-bit octets and no wchar_t should
>>be needed at all.
>>
> UTF-8 fits in a stream of 8-bit octets of the *external* encoding!
> How do you produce this *external* UTF-8 encoded stream?
>
> The standard way is using an *internal* wchar_t representation
> (basically, on GNU systems is UCS4, see the glibc docs), then
> exploiting the specialization codecvt<wchar_t, char, mbstate_t>.
So how do you do that? I currently use an ostringstream, how would I
go about getting a std::string in the encoding of the current locale?
Can I persuade you to show how this snippet should look like (where
locale_to_utf8 takes a std::string in the encoding of the current
locale and returns it as UTF-8):
std::ostringstream os;
os.imbue(std::locale("")); // use the user's locale for the stream
os << obj;
return Glib::locale_to_utf8(os.str());
That would be a tremendous help. Then I would at least be sure to get
it right this time. :-)
Most of the other things you said more or less went over my head,
although I'm think I'm beginning to understand it now. Perhaps I
should clarify: I was not really arguing about anything, I was just
asking out of ignorance.
--
Ole Laursen
http://www.cs.aau.dk/~olau/