Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/ev-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/ev-utils.c')
-rw-r--r--shell/ev-utils.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/shell/ev-utils.c b/shell/ev-utils.c
index 13f1459..540836f 100644
--- a/shell/ev-utils.c
+++ b/shell/ev-utils.c
@@ -400,3 +400,43 @@ get_gdk_pixbuf_format_by_extension (gchar *uri)
return NULL;
}
+#define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
+#define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
+
+static char *
+uri_decoded_copy (const char *part, int length)
+{
+ unsigned char *s, *d;
+ char *decoded = g_strndup (part, length);
+
+ s = d = (unsigned char *)decoded;
+ do {
+ if (*s == '%') {
+ if (!g_ascii_isxdigit (s[1]) ||
+ !g_ascii_isxdigit (s[2])) {
+ g_free (decoded);
+ return NULL;
+ }
+ *d++ = HEXCHAR (s);
+ s += 2;
+ } else
+ *d++ = *s;
+ } while (*s++);
+
+ return decoded;
+}
+
+char* escape_uri_for_display (const char *uri)
+{
+ GFile *file;
+ char *disp;
+ char *filename;
+
+ file = g_file_new_for_uri (uri);
+ filename = g_file_get_parse_name (file);
+ disp = uri_decoded_copy (filename, strlen (filename));
+ g_free (filename);
+ g_object_unref (file);
+
+ return disp;
+}