Glib::
2014-03-04 2:08 GMT+01:00 Jon Cruz <jon@...18...>:
Some of it depends on where in the program the strings are going to be used.
In general we want to keep the core of our software to purely Unicode. In our case with GTK+ and GLib that means UTF-8.
User data *may* come in and out of certain points in the locale encoding. For those cases we need to convert appropriately.
Then file IO will be in the filesystem encoding. There too we probably want to convert fairly soon to UTF-8 data, and as we go out to the file system we'll have to convert back. Certain systems may have paths that don't convert cleanly to UTF-8. However those files and/or directories won't show up properly in file browsers, GNOME desktop, etc. so it might be fine to punt on those.
Fortunately, paths untranslatable to UTF-8 can only happen on some old and/or strangely configured Linux systems which use a filename encoding different than UTF-8. On Windows, the filename encoding is always UTF-8 (Glib/GTK convert it transparently to/from UTF-16 used in Windows system calls). I'm not completely sure about OS X, but it also seems to use UTF-8.
To support those old systems, local filenames should be in std::string and almost everything else in Glib::ustring.
For more advanced use, we might add a system that maps untranslatable file-system paths to a corresponding UI string. And/or we could create a complex data type that included the filesystem string and the 'user/UI' string. These might be extreme measures, though.
I think this is not necessary. The "std::string for filenames, Glib::ustring for everything else" convention recommended in the Glib/GTK manuals takes care of all relevant cases.
Another big gotcha is that URI's are tricky, and the standard is very limited in character set. This then leads to most of the URI support in GTK+/GLib being unusable for our needs. Technically I think we actually might need IRI's.
URIs as used in Glib for file access should contain URL-escaped bytes in the filename encoding, so again there is little potential for error as long as we ignore old / strange Linux.
The functions Glib::filename_from_uri and Glib::filename_to_uri can be used to convert between local filenames and URIs.
https://developer.gnome.org/glibmm/2.35/group__CharsetConv.html
Regards, Krzysztof