]> git.0d.be Git - empathy.git/commitdiff
Extract empathy_string_parser_link and empathy_string_parser_escape from empathy...
authorXavier Claessens <xclaesse@gmail.com>
Sun, 1 Nov 2009 10:19:57 +0000 (11:19 +0100)
committerXavier Claessens <xclaesse@gmail.com>
Tue, 24 Nov 2009 17:29:44 +0000 (18:29 +0100)
libempathy-gtk/empathy-theme-adium.c
libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h

index 014cd87f0ee6c22f1f8eaa86fed5d2924de0227f..f1da329e3748122761d749aeff598b2a0b6937b2 100644 (file)
@@ -191,19 +191,6 @@ theme_adium_open_address_cb (GtkMenuItem *menuitem,
        g_free (uri);
 }
 
-static void
-theme_adium_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);
-}
-
 static void
 theme_adium_parser_newline (GString *string,
                            const gchar *text,
@@ -281,60 +268,11 @@ theme_adium_parser_smiley (GString *string,
        empathy_string_parser_substr (string, text + last, len - last, user_data);
 }
 
-static void
-theme_adium_parser_url (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);
-}
-
 static EmpathyStringParser string_parsers[] = {
-       theme_adium_parser_url,
+       empathy_string_parser_link,
        theme_adium_parser_smiley,
        theme_adium_parser_newline,
-       theme_adium_parser_escape,
+       empathy_string_parser_escape,
        NULL,
 };
 
index 376d1f9d896807c5b6eb0b15d87435122283d7c6..289874eb78f7c482967bc542a559ed7769fcc931 100644 (file)
@@ -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);
+}
+
index 58960c305339cd18dd853db46436c86162c12646..80332c98ff5f8e3621ca4dea7550c2ac80d10bda 100644 (file)
@@ -129,6 +129,18 @@ empathy_string_parser_substr (GString *string,
                              gssize len,
                              EmpathyStringParser *parsers);
 
+void
+empathy_string_parser_link (GString *string,
+                           const gchar *text,
+                           gssize len,
+                           gpointer user_data);
+
+void
+empathy_string_parser_escape (GString *string,
+                             const gchar *text,
+                             gssize len,
+                             gpointer user_data);
+
 G_END_DECLS
 
 #endif /*  __EMPATHY_UI_UTILS_H__ */