Improve and optimize sokoke_uri_to_ascii to parse about:version

This commit is contained in:
Christian Dywan 2010-02-12 02:08:05 +01:00
parent ca3e86cbce
commit 902f836810
2 changed files with 18 additions and 17 deletions

View file

@ -424,9 +424,9 @@ sokoke_spawn_program (const gchar* command,
* @uri: an URI string * @uri: an URI string
* @path: location of a string pointer * @path: location of a string pointer
* *
* Returns the hostname of the specified URI, * Returns the hostname of the specified URI.
* and stores the path in @path. *
* @path is at least set to "" * If there is a path, it is stored in @path.
* *
* Return value: a newly allocated hostname * Return value: a newly allocated hostname
**/ **/
@ -436,19 +436,17 @@ sokoke_hostname_from_uri (const gchar* uri,
{ {
gchar* hostname; gchar* hostname;
*path = ""; if ((hostname = strchr (uri, '/')))
if ((hostname = g_utf8_strchr (uri, -1, '/')))
{ {
if (hostname[1] == '/') if (hostname[1] == '/')
hostname += 2; hostname += 2;
if ((*path = g_utf8_strchr (hostname, -1, '/'))) if ((*path = strchr (hostname, '/')))
hostname = g_strndup (hostname, *path - hostname); return g_strndup (hostname, *path - hostname);
else else
hostname = g_strdup (hostname); return g_strdup (hostname);
} }
else
hostname = g_strdup (uri); return g_strdup (uri);
return hostname;
} }
/** /**
@ -498,9 +496,12 @@ sokoke_hostname_to_ascii (const gchar* hostname)
gchar* gchar*
sokoke_uri_to_ascii (const gchar* uri) 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; gulong offset;
gchar* buffer; gchar* buffer;
@ -511,9 +512,8 @@ sokoke_uri_to_ascii (const gchar* uri)
proto = buffer; proto = buffer;
} }
gchar* path; hostname = sokoke_hostname_from_uri (uri, &path);
gchar* hostname = sokoke_hostname_from_uri (uri, &path); encoded = sokoke_hostname_to_ascii (hostname);
gchar* encoded = sokoke_hostname_to_ascii (hostname);
if (encoded) if (encoded)
{ {
@ -648,7 +648,7 @@ sokoke_format_uri_for_display (const gchar* uri)
{ {
gchar* unescaped = g_uri_unescape_string (uri, " +"); gchar* unescaped = g_uri_unescape_string (uri, " +");
#ifdef HAVE_LIBSOUP_2_27_90 #ifdef HAVE_LIBSOUP_2_27_90
gchar* path; gchar* path = NULL;
gchar* hostname; gchar* hostname;
gchar* decoded; gchar* decoded;

View file

@ -133,6 +133,7 @@ magic_uri_idn (void)
#endif #endif
{ "http://en.wikipedia.org/wiki/Kölsch_language", NULL }, { "http://en.wikipedia.org/wiki/Kölsch_language", NULL },
{ "file:///home/mark/frühstück", NULL }, { "file:///home/mark/frühstück", NULL },
{ "about:version", NULL },
}; };
guint i; guint i;