empathy r2549 - trunk/libempathy-gtk



Author: xclaesse
Date: Tue Mar  3 09:46:50 2009
New Revision: 2549
URL: http://svn.gnome.org/viewvc/empathy?rev=2549&view=rev

Log:
Move URI regex to empathy-ui-utils

From: Xavier Claessens <xclaesse gmail com>

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

Modified: trunk/libempathy-gtk/empathy-chat-text-view.c
==============================================================================
--- trunk/libempathy-gtk/empathy-chat-text-view.c	(original)
+++ trunk/libempathy-gtk/empathy-chat-text-view.c	Tue Mar  3 09:46:50 2009
@@ -62,15 +62,6 @@
 #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 @@
 	GtkTextIter              start_iter, end_iter;
 	GtkTextMark             *mark;
 	GtkTextIter              iter;
+	GRegex                  *uri_regex;
 	GMatchInfo              *match_info;
 	gboolean                 match;
 	gint                     last = 0;
@@ -1275,10 +1267,7 @@
 	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 @@
 		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);

Modified: trunk/libempathy-gtk/empathy-ui-utils.c
==============================================================================
--- trunk/libempathy-gtk/empathy-ui-utils.c	(original)
+++ trunk/libempathy-gtk/empathy-ui-utils.c	Tue Mar  3 09:46:50 2009
@@ -53,6 +53,14 @@
 #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 @@
 	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;

Modified: trunk/libempathy-gtk/empathy-ui-utils.h
==============================================================================
--- trunk/libempathy-gtk/empathy-ui-utils.h	(original)
+++ trunk/libempathy-gtk/empathy-ui-utils.h	Tue Mar  3 09:46:50 2009
@@ -63,6 +63,8 @@
 } 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,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]