aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2009-03-03 17:46:50 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2009-03-03 17:46:50 +0800
commitba7eae326c9cd3e12447bf636cedfae6284b2581 (patch)
tree25d1aec934c513dc6165b59fb7d6a8430713c319 /libempathy-gtk
parent02c2e9960f1a66ed3661e67f1038a6aeea7a2d69 (diff)
downloadgsoc2013-empathy-ba7eae326c9cd3e12447bf636cedfae6284b2581.tar
gsoc2013-empathy-ba7eae326c9cd3e12447bf636cedfae6284b2581.tar.gz
gsoc2013-empathy-ba7eae326c9cd3e12447bf636cedfae6284b2581.tar.bz2
gsoc2013-empathy-ba7eae326c9cd3e12447bf636cedfae6284b2581.tar.lz
gsoc2013-empathy-ba7eae326c9cd3e12447bf636cedfae6284b2581.tar.xz
gsoc2013-empathy-ba7eae326c9cd3e12447bf636cedfae6284b2581.tar.zst
gsoc2013-empathy-ba7eae326c9cd3e12447bf636cedfae6284b2581.zip
Move URI regex to empathy-ui-utils
From: Xavier Claessens <xclaesse@gmail.com> svn path=/trunk/; revision=2549
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-chat-text-view.c16
-rw-r--r--libempathy-gtk/empathy-ui-utils.c21
-rw-r--r--libempathy-gtk/empathy-ui-utils.h2
3 files changed, 26 insertions, 13 deletions
diff --git a/libempathy-gtk/empathy-chat-text-view.c b/libempathy-gtk/empathy-chat-text-view.c
index f645cf88c..f15d076ff 100644
--- a/libempathy-gtk/empathy-chat-text-view.c
+++ b/libempathy-gtk/empathy-chat-text-view.c
@@ -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 @@ 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);
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 692b6ff7d..9e8928e8e 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -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 @@ 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;
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index 69ec465be..64c1f1a14 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -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,