diff options
Diffstat (limited to '')
-rw-r--r-- | utils.vala | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/utils.vala b/utils.vala new file mode 100644 index 0000000..845728b --- /dev/null +++ b/utils.vala @@ -0,0 +1,27 @@ +class Utils { + public static string? normalize_uri(string? uri) { + if (uri == null) + return null; + + string? u = Uri.unescape_string(uri, null); + + if (u == null) + u = uri; + + if (u.has_prefix("ftp://") || u.has_prefix("http://") || u.has_prefix("https://")) { + int a = u.index_of("/", 0) + 2; // character after second slash + int b = u.index_of("/", a); // next slash after hostname... + if (b < 0) + b = u.length; // ... or end of string + + string hostname = u.slice(a, b); + string? canon = Hostname.to_unicode(hostname); + + if (canon != null && hostname != canon) { + u = u.splice(a, b, canon); + } + } + + return u; + } +} |