3 ms·
The GFile API in GTK+'s underlying glib family of libraries kind of has this, at least for your example of filenames. It separates the "actual" name of a file f
by unwind 7y ago
The GFile API in GTK+'s underlying glib family of libraries kind of has this, at least for your example of filenames. It separates the "actual" name of a file from it's display name, and has APIs to support that division.
From the documentation [1]:
All GFiles have a basename (get with g_file_get_basename()). These names are byte strings that are used to identify the file on the filesystem (relative to its parent directory) and there is no guarantees that they have any particular charset encoding or even make any sense at all. If you want to use filenames in a user interface you should use the display name that you can get by requesting the G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info(). This is guaranteed to be in UTF-8 and can be used in a user interface. But always store the real basename or the GFile to use to actually access the file, because there is no way to go from a display name to the actual name.
This makes implementing things that deal with filenames a lot (like, cough, a file manager) quite interesting.
[1] https://developer.gnome.org/gio/stable/GFile.html https://developer.gnome.org/gio/stable/GFile.html
- rhn_mk1 7y agoThere's a similar concept in Rust, where filename strings are OsString https://doc.rust-lang.org/std/ffi/struct.OsString.html https://doc.rust-lang.org/std/ffi/struct.OsString.html , which can be converted to the Unicode-like String.
- ncmncm 7y agoWith perhaps Rust's greatest contribution to the public discourse, the WTF-8 format.