aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-ui-utils.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2009-11-01 18:19:57 +0800
committerXavier Claessens <xclaesse@gmail.com>2009-11-25 01:29:44 +0800
commit1d42b9fde60750fab76d7af606388bc28b1083ad (patch)
tree3a451c7d1e9d7be9f224e60a2f1c04e24272843d /libempathy-gtk/empathy-ui-utils.c
parent6ea436c8b313974d94eb9fe97974edcf4f47e46d (diff)
downloadgsoc2013-empathy-1d42b9fde60750fab76d7af606388bc28b1083ad.tar
gsoc2013-empathy-1d42b9fde60750fab76d7af606388bc28b1083ad.tar.gz
gsoc2013-empathy-1d42b9fde60750fab76d7af606388bc28b1083ad.tar.bz2
gsoc2013-empathy-1d42b9fde60750fab76d7af606388bc28b1083ad.tar.lz
gsoc2013-empathy-1d42b9fde60750fab76d7af606388bc28b1083ad.tar.xz
gsoc2013-empathy-1d42b9fde60750fab76d7af606388bc28b1083ad.tar.zst
gsoc2013-empathy-1d42b9fde60750fab76d7af606388bc28b1083ad.zip
Extract empathy_string_parser_link and empathy_string_parser_escape from empathy-theme-adium.c
Diffstat (limited to 'libempathy-gtk/empathy-ui-utils.c')
-rw-r--r--libempathy-gtk/empathy-ui-utils.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 376d1f9d8..289874eb7 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -1583,3 +1583,65 @@ empathy_string_parser_substr (GString *string,
}
}
+void
+empathy_string_parser_link (GString *string,
+ const gchar *text,
+ gssize len,
+ gpointer user_data)
+{
+ GRegex *uri_regex;
+ GMatchInfo *match_info;
+ gboolean match;
+ gint last = 0;
+
+ /* Add <a href></a> arround links */
+ uri_regex = empathy_uri_regex_dup_singleton ();
+ match = g_regex_match_full (uri_regex, text, len, 0, 0, &match_info, NULL);
+ if (match) {
+ gint s = 0, e = 0;
+
+ do {
+ gchar *real_url;
+
+ g_match_info_fetch_pos (match_info, 0, &s, &e);
+
+ if (s > last) {
+ /* Append the text between last link (or the
+ * start of the message) and this link */
+ empathy_string_parser_substr (string, text + last,
+ s - last,
+ user_data);
+ }
+
+ /* Append the link inside <a href=""></a> tag */
+ real_url = empathy_make_absolute_url_len (text + s, e - s);
+
+ g_string_append_printf (string, "<a href=\"%s\">",
+ real_url);
+ g_string_append_len (string, text + s, e - s);
+ g_string_append (string, "</a>");
+
+ g_free (real_url);
+ last = e;
+ } while (g_match_info_next (match_info, NULL));
+ }
+
+ empathy_string_parser_substr (string, text + last, len - last, user_data);
+
+ g_match_info_free (match_info);
+ g_regex_unref (uri_regex);
+}
+
+void
+empathy_string_parser_escape (GString *string,
+ const gchar *text,
+ gssize len,
+ gpointer user_data)
+{
+ gchar *escaped;
+
+ escaped = g_markup_escape_text (text, len);
+ g_string_append (string, escaped);
+ g_free (escaped);
+}
+