Re: Exposing get_filename_charset

Alexander Larsson writes:
 > The local files part of nautilus_file_get_display_name currently goes
 > like:

If I understood that code correctly, it patches the display name
together from valid UTF-8 snippets in the string and question marks? I
think instead of question marks it would be more useful to use
something like g_strescape() of the whole string. I don't think file
names that are partially in UTF-8 and partially in something else
occur very often, so using the portions of the string that happen to
be valid UTF-8 as such is probably wrong, and it would be better to
just output all of the non-ASCII bytes in octal or hex.

Would this be OK:

 * g_filename_get_display_name:
 * filename: A filename in unknown encoding
 * Returns a UTF-8 version of a filename in unknown encoding. If the
 * filename is valid in the GLib file name encoding, i.e. if
 * g_filename_to_utf8() succeeds, the result of that is
 * returned. Otherwise nonprintable and non-ASCII characters in the
 * filename are replaced with C-like escape sequences, see
 * g_strescape(). The result is thus not intended to be used as a file
 * name, but for error messages and such.
 * Returns: A newly-allocated string that should be freed with
 * g_free() after use.
gchar *
g_filename_display_name (const gchar *filename)
  gchar *result = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);

  if (result != NULL)
    return result;

  return g_strescape (filename, NULL);


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