Re: gtkmm 4: Glib::ustring: implicit conversions with streams



On 20 December 2016 at 09:26, Kjell Ahlstedt wrote:

The conversions done by Glib::ustring are reasonable, at least if the read
or written stream uses the global locale. A std::locale contains a codecvt
facet, used for converting between one character encoding in the stream
(file) and a possibly different character encoding in main memory. But
Glib::ustring shall always contain UTF-8 encoded characters, independent of
the stream's locale and codecvt facet. It's reasonable that ustring's
operator<<() and operator>>() convert between UTF-8 and the stream's main
memory encoding.

I get horribly confused by C++ locales, and especially the character
encoding parts, but I think streams expect to receive characters in
the native character set, so I think using the global locale is
correct. That gives you a conversion from UTF-8 to the native
character set, which gives you something in the encoding that streams
expect.

When a stream wants to perform a conversion using its imbued locale it
already knows how to do that, e.g. std::filebuf does that so that
bytes written to a file are converted from the in-memory encoding to
the on-disk encoding.

But as I said, I find this stuff very confusing.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]