aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-12-01 18:21:55 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-12-01 18:21:55 +0800
commitbebba4972777e1dde7e7087cb27dc75b83a3c38a (patch)
tree5cfffa1424d24dbf711d577cf32fdefe2827a722 /libempathy-gtk
parent60cdd53fa93638f37eb53139eae0d5d4e008880d (diff)
downloadgsoc2013-empathy-bebba4972777e1dde7e7087cb27dc75b83a3c38a.tar
gsoc2013-empathy-bebba4972777e1dde7e7087cb27dc75b83a3c38a.tar.gz
gsoc2013-empathy-bebba4972777e1dde7e7087cb27dc75b83a3c38a.tar.bz2
gsoc2013-empathy-bebba4972777e1dde7e7087cb27dc75b83a3c38a.tar.lz
gsoc2013-empathy-bebba4972777e1dde7e7087cb27dc75b83a3c38a.tar.xz
gsoc2013-empathy-bebba4972777e1dde7e7087cb27dc75b83a3c38a.tar.zst
gsoc2013-empathy-bebba4972777e1dde7e7087cb27dc75b83a3c38a.zip
Use GRegex instead of custom code and use a new regex to detect URIs
svn path=/trunk/; revision=1932
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-theme.c104
1 files changed, 51 insertions, 53 deletions
diff --git a/libempathy-gtk/empathy-theme.c b/libempathy-gtk/empathy-theme.c
index e2da4e494..d68b72f02 100644
--- a/libempathy-gtk/empathy-theme.c
+++ b/libempathy-gtk/empathy-theme.c
@@ -34,7 +34,17 @@
/* Number of seconds between timestamps when using normal mode, 5 minutes. */
#define TIMESTAMP_INTERVAL 300
+#define SHEMES "(https?|ftps?|nntp|news|javascript|about|ghelp|apt|telnet|"\
+ "file|webcal|mailto)"
+#define SEPARATOR "([^,;\?><()\\ ])"
+#define BODY "([^\\ ]*(\\\\ )?)+"
+#define URI_REGEX "("SHEMES"://"BODY SEPARATOR")" \
+ "|((mailto:)?"BODY"@"BODY"."BODY SEPARATOR")"\
+ "|((www|ftp)."BODY SEPARATOR")"
+static GRegex *uri_regex = NULL;
+
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTheme)
+
typedef struct {
EmpathySmileyManager *smiley_manager;
gboolean show_avatars;
@@ -254,8 +264,11 @@ empathy_theme_append_text (EmpathyTheme *theme,
GtkTextIter start_iter, end_iter;
GtkTextMark *mark;
GtkTextIter iter;
- gint num_matches, i;
- GArray *start, *end;
+ GMatchInfo *match_info;
+ gboolean match;
+ gint last = 0;
+ gint s = 0, e = 0;
+ gchar *tmp;
priv = GET_PRIV (theme);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -263,57 +276,17 @@ empathy_theme_append_text (EmpathyTheme *theme,
gtk_text_buffer_get_end_iter (buffer, &start_iter);
mark = gtk_text_buffer_create_mark (buffer, NULL, &start_iter, TRUE);
- start = g_array_new (FALSE, FALSE, sizeof (gint));
- end = g_array_new (FALSE, FALSE, sizeof (gint));
-
- num_matches = empathy_regex_match (EMPATHY_REGEX_ALL, body, start, end);
-
- if (num_matches == 0) {
- gtk_text_buffer_get_end_iter (buffer, &iter);
- theme_insert_text_with_emoticons (buffer, &iter, body, priv->smiley_manager);
- } else {
- gint last = 0;
- gint s = 0, e = 0;
- gchar *tmp;
-
- for (i = 0; i < num_matches; i++) {
- s = g_array_index (start, gint, i);
- e = g_array_index (end, gint, i);
-
- if (s > last) {
- tmp = empathy_substring (body, last, s);
-
- gtk_text_buffer_get_end_iter (buffer, &iter);
- theme_insert_text_with_emoticons (buffer,
- &iter,
- tmp,
- priv->smiley_manager);
- g_free (tmp);
- }
-
- tmp = empathy_substring (body, s, e);
-
- gtk_text_buffer_get_end_iter (buffer, &iter);
- if (!link_tag) {
- gtk_text_buffer_insert (buffer, &iter,
- tmp, -1);
- } {
- gtk_text_buffer_insert_with_tags_by_name (buffer,
- &iter,
- tmp,
- -1,
- link_tag,
- "link",
- NULL);
- }
-
- g_free (tmp);
+ if (!uri_regex) {
+ uri_regex = g_regex_new (URI_REGEX, 0, 0, NULL);
+ }
- last = e;
- }
+ 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))
+ continue;
- if (e < strlen (body)) {
- tmp = empathy_substring (body, e, strlen (body));
+ if (s > last) {
+ tmp = empathy_substring (body, last, s);
gtk_text_buffer_get_end_iter (buffer, &iter);
theme_insert_text_with_emoticons (buffer,
@@ -322,10 +295,35 @@ empathy_theme_append_text (EmpathyTheme *theme,
priv->smiley_manager);
g_free (tmp);
}
+
+ tmp = empathy_substring (body, s, e);
+
+ gtk_text_buffer_get_end_iter (buffer, &iter);
+ if (!link_tag) {
+ gtk_text_buffer_insert (buffer, &iter,
+ tmp, -1);
+ } else {
+ gtk_text_buffer_insert_with_tags_by_name (buffer,
+ &iter,
+ tmp,
+ -1,
+ link_tag,
+ "link",
+ NULL);
+ }
+
+ g_free (tmp);
+ last = e;
}
+ g_match_info_free (match_info);
- g_array_free (start, TRUE);
- g_array_free (end, TRUE);
+ if (last < strlen (body)) {
+ gtk_text_buffer_get_end_iter (buffer, &iter);
+ theme_insert_text_with_emoticons (buffer,
+ &iter,
+ body + last,
+ priv->smiley_manager);
+ }
gtk_text_buffer_get_end_iter (buffer, &iter);
gtk_text_buffer_insert (buffer, &iter, "\n", 1);