]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-ui-utils.c
Move URI regex to empathy-ui-utils
[empathy.git] / libempathy-gtk / empathy-ui-utils.c
index 692b6ff7d82f6d44764a3152d79d32c3b07c2024..9e8928e8e46e3340eb2e2a74391d39ec23b16e62 100644 (file)
 #include <libempathy/empathy-idle.h>
 #include <libempathy/empathy-tp-file.h>
 
+#define SCHEMES "(https?|s?ftps?|nntp|news|javascript|about|ghelp|apt|telnet|"\
+               "file|webcal|mailto)"
+#define BODY "([^\\ \\n]+)"
+#define END_BODY "([^\\ \\n]*[^,;\?><()\\ \"\\.\\n])"
+#define URI_REGEX "("SCHEMES"://"END_BODY")" \
+                 "|((mailto:)?"BODY"@"BODY"\\."END_BODY")"\
+                 "|((www|ftp)\\."END_BODY")"
+
 void
 empathy_gtk_init (void)
 {
@@ -68,6 +76,19 @@ empathy_gtk_init (void)
        initialized = TRUE;
 }
 
+GRegex *
+empathy_uri_regex_dup_singleton (void)
+{
+       static GRegex *uri_regex = NULL;
+
+       /* We intentionally leak the regex so it's not recomputed */
+       if (!uri_regex) {
+               uri_regex = g_regex_new (URI_REGEX, 0, 0, NULL);
+       }
+
+       return g_regex_ref (uri_regex);
+}
+
 struct SizeData {
        gint     width;
        gint     height;