[Xfce4-commits] <midori:master> Improve and optimize sokoke_uri_to_ascii to parse about:version

Christian Dywan noreply at xfce.org
Fri Feb 12 02:22:02 CET 2010


Updating branch refs/heads/master
         to 902f8368101cd0ca6397d0b9964dea7760b778fa (commit)
       from ca3e86cbce43636f4c73eb37f3ad463b64cdee77 (commit)

commit 902f8368101cd0ca6397d0b9964dea7760b778fa
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Feb 12 02:08:05 2010 +0100

    Improve and optimize sokoke_uri_to_ascii to parse about:version

 midori/sokoke.c   |   34 +++++++++++++++++-----------------
 tests/magic-uri.c |    1 +
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/midori/sokoke.c b/midori/sokoke.c
index 2e5a368..3f50fdc 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -424,9 +424,9 @@ sokoke_spawn_program (const gchar* command,
  * @uri: an URI string
  * @path: location of a string pointer
  *
- * Returns the hostname of the specified URI,
- * and stores the path in @path.
- * @path is at least set to ""
+ * Returns the hostname of the specified URI.
+ *
+ * If there is a path, it is stored in @path.
  *
  * Return value: a newly allocated hostname
  **/
@@ -436,19 +436,17 @@ sokoke_hostname_from_uri (const gchar* uri,
 {
     gchar* hostname;
 
-    *path = "";
-    if ((hostname = g_utf8_strchr (uri, -1, '/')))
+    if ((hostname = strchr (uri, '/')))
     {
         if (hostname[1] == '/')
             hostname += 2;
-        if ((*path = g_utf8_strchr (hostname, -1, '/')))
-            hostname = g_strndup (hostname, *path - hostname);
+        if ((*path = strchr (hostname, '/')))
+            return g_strndup (hostname, *path - hostname);
         else
-            hostname = g_strdup (hostname);
+            return g_strdup (hostname);
     }
-    else
-        hostname = g_strdup (uri);
-    return hostname;
+
+    return g_strdup (uri);
 }
 
 /**
@@ -498,9 +496,12 @@ sokoke_hostname_to_ascii (const gchar* hostname)
 gchar*
 sokoke_uri_to_ascii (const gchar* uri)
 {
-    gchar* proto;
+    gchar* proto = NULL;
+    gchar* path = NULL;
+    gchar* hostname;
+    gchar* encoded;
 
-    if ((proto = g_utf8_strchr (uri, -1, ':')))
+    if (strchr (uri, '/') && (proto = strchr (uri, ':')))
     {
         gulong offset;
         gchar* buffer;
@@ -511,9 +512,8 @@ sokoke_uri_to_ascii (const gchar* uri)
         proto = buffer;
     }
 
-    gchar* path;
-    gchar* hostname = sokoke_hostname_from_uri (uri, &path);
-    gchar* encoded = sokoke_hostname_to_ascii (hostname);
+    hostname = sokoke_hostname_from_uri (uri, &path);
+    encoded = sokoke_hostname_to_ascii (hostname);
 
     if (encoded)
     {
@@ -648,7 +648,7 @@ sokoke_format_uri_for_display (const gchar* uri)
     {
         gchar* unescaped = g_uri_unescape_string (uri, " +");
         #ifdef HAVE_LIBSOUP_2_27_90
-        gchar* path;
+        gchar* path = NULL;
         gchar* hostname;
         gchar* decoded;
 
diff --git a/tests/magic-uri.c b/tests/magic-uri.c
index 74ee243..9886bdb 100644
--- a/tests/magic-uri.c
+++ b/tests/magic-uri.c
@@ -133,6 +133,7 @@ magic_uri_idn (void)
     #endif
     { "http://en.wikipedia.org/wiki/Kölsch_language", NULL },
     { "file:///home/mark/frühstück", NULL },
+    { "about:version", NULL },
      };
     guint i;
 



More information about the Xfce4-commits mailing list