Re: ustring::validate() costs?



The right way to do it is to set the G_FILENAME_ENCODING or G_BROKEN_FILENAMES environmental variable in /etc/profile or an executable shell file in /etc/profile.d, depending on your distribution (which is how system wide environmental variable should be set), and then use Glib::filename_to_utf8(). This will enable your code to be usable (if G_FILENAME_ENCODING is appropriately set by the user) with filenames in other than the UTF-8 or the local system's locale codeset.

Okay, I see. I guess my system is really messed up then, since I obviously have exactly this problem: Some (or even most) of my files are neither encoded in UTF-8 nor in my locale's encoding (that's why g_filename_to_utf8() fails because I haven't set these variables properly).

It would be nice to figure out in my program for /each/ file I read, in which character set it is encoded. Is this possible? I only found functions so far which can either read the locale's character set or check if some filename is valid UTF-8 (or not), but no function which individually probes for a certain file in which character set its filename is encoded.

This would solve my problem, since I could then use Glib::convert() directly to convert from and to the correct encoding for each filename individually. Maybe this is how Nautilus does it (since it doesn't have any problems reading my files, I guess it has at least /some/ clever mechanism to detect for each file if a conversion is necessary and if so, from which character encoding it has to convert to UTF-8). Looks as if I have to peek at the Nautilus source again, but if you have any good ideas how to solve this without setting these environment variables I'm all ears :)

Thanks,
Matthias




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