An issue with non-utf locale and g_format_size_full
Glib based programs create a nice illusion that you can work with everything in UTF-8, except for some corner cases like filenames where you need to take more care. I've found that this illusion fails in some other cases too.
If you run the following test program with LC_ALL=cs_CZ.iso-8859-2, the output of the first and third g_print complains about invalid UTF-8 string. Internally g_format_size_full uses g_string_printf for number formatting that outputs strings in the encoding set by the locale, but glib expects UTF-8 strings internally.
I don't think this is easily solvable without forcing the underlying sprintf calls to output UTF-8 encoded strings or replacing them entirely, because I'd expect that I can use utf-8 in g_strdup_printf("číslo %f'.2", 123456), and it will produce a mixed encoding result as of now.
#include <glib.h>
#include <locale.h>
int main(void) {
setlocale(LC_ALL, "");
g_print("%s\n", g_strdup_printf("%'.2f", 123456789.0));
g_print("%s\n", "nech to koňovi, má větší hlavu");
g_print("%s\n", g_format_size_full(123456789, G_FORMAT_SIZE_LONG_FORMAT | G_FORMAT_SIZE_IEC_UNITS));
return 0;
}
[Invalid UTF-8] 123\xa0456\xa0789,00
nech to koňovi, má větší hlavu
[Invalid UTF-8] 117,7\xc2\xa0MiB (123\xa0456\xa0789\xc2\xa0bajt\xc5\xaf)
https://cs.wikipedia.org/wiki/ISO_8859-2
\xa0 is NBSP non-breakable space
I frankly don't know where \xc2 is getting from.