]> git.0d.be Git - empathy.git/commitdiff
Move URI regex to empathy-ui-utils
authorXavier Claessens <xclaesse@gmail.com>
Tue, 3 Mar 2009 09:46:50 +0000 (09:46 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Tue, 3 Mar 2009 09:46:50 +0000 (09:46 +0000)
From: Xavier Claessens <xclaesse@gmail.com>

svn path=/trunk/; revision=2549

libempathy-gtk/empathy-chat-text-view.c
libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h

index f645cf88c1235ac3a7b54928fbb3f19362b35fbc..f15d076ff20152e2407e66e67f567b0491c16fd2 100644 (file)
 #define MAX_SCROLL_TIME 0.4 /* seconds */
 #define SCROLL_DELAY 33     /* milliseconds */
 
-#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")"
-static GRegex *uri_regex = NULL;
-
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatTextView)
 
 typedef struct {
@@ -1264,6 +1255,7 @@ empathy_chat_text_view_append_body (EmpathyChatTextView *view,
        GtkTextIter              start_iter, end_iter;
        GtkTextMark             *mark;
        GtkTextIter              iter;
+       GRegex                  *uri_regex;
        GMatchInfo              *match_info;
        gboolean                 match;
        gint                     last = 0;
@@ -1275,10 +1267,7 @@ empathy_chat_text_view_append_body (EmpathyChatTextView *view,
        gtk_text_buffer_get_end_iter (priv->buffer, &start_iter);
        mark = gtk_text_buffer_create_mark (priv->buffer, NULL, &start_iter, TRUE);
 
-       if (!uri_regex) {
-               uri_regex = g_regex_new (URI_REGEX, 0, 0, NULL);
-       }
-
+       uri_regex = empathy_uri_regex_dup_singleton ();
        for (match = g_regex_match (uri_regex, body, 0, &match_info); match;
             match = g_match_info_next (match_info, NULL)) {
                if (!g_match_info_fetch_pos (match_info, 0, &s, &e))
@@ -1308,6 +1297,7 @@ empathy_chat_text_view_append_body (EmpathyChatTextView *view,
                last = e;
        }
        g_match_info_free (match_info);
+       g_regex_unref (uri_regex);
 
        if (last < strlen (body)) {
                gtk_text_buffer_get_end_iter (priv->buffer, &iter);
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;
index 69ec465bebec22de231dbc26661325f9ea95c59e..64c1f1a143cbe7b1af1bc4e1f011993a46dc4b15 100644 (file)
@@ -63,6 +63,8 @@ typedef enum {
 } EmpathySound;
 
 void            empathy_gtk_init                        (void);
+GRegex *        empathy_uri_regex_dup_singleton         (void);
+
 /* Glade */
 void            empathy_glade_get_file_simple           (const gchar      *filename,
                                                         const gchar      *root,