diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2009-11-01 18:04:00 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2009-11-25 01:29:44 +0800 |
commit | 6ea436c8b313974d94eb9fe97974edcf4f47e46d (patch) | |
tree | a3712e0599afc03b44fa49d4b0614278b3f68257 /libempathy-gtk/empathy-theme-adium.c | |
parent | b15f926089b6b718004467c8bb2ddf6f6cd3a9ac (diff) | |
download | gsoc2013-empathy-6ea436c8b313974d94eb9fe97974edcf4f47e46d.tar gsoc2013-empathy-6ea436c8b313974d94eb9fe97974edcf4f47e46d.tar.gz gsoc2013-empathy-6ea436c8b313974d94eb9fe97974edcf4f47e46d.tar.bz2 gsoc2013-empathy-6ea436c8b313974d94eb9fe97974edcf4f47e46d.tar.lz gsoc2013-empathy-6ea436c8b313974d94eb9fe97974edcf4f47e46d.tar.xz gsoc2013-empathy-6ea436c8b313974d94eb9fe97974edcf4f47e46d.tar.zst gsoc2013-empathy-6ea436c8b313974d94eb9fe97974edcf4f47e46d.zip |
Create API for generic string parser
Diffstat (limited to 'libempathy-gtk/empathy-theme-adium.c')
-rw-r--r-- | libempathy-gtk/empathy-theme-adium.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index a83b8da86..014cd87f0 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -194,7 +194,8 @@ theme_adium_open_address_cb (GtkMenuItem *menuitem, static void theme_adium_parser_escape (GString *string, const gchar *text, - gssize len) + gssize len, + gpointer user_data) { gchar *escaped; @@ -206,7 +207,8 @@ theme_adium_parser_escape (GString *string, static void theme_adium_parser_newline (GString *string, const gchar *text, - gssize len) + gssize len, + gpointer user_data) { gint i; gint prev = 0; @@ -218,18 +220,20 @@ theme_adium_parser_newline (GString *string, /* Replace \n by <br/> */ for (i = 0; i < len && text[i] != '\0'; i++) { if (text[i] == '\n') { - theme_adium_parser_escape (string, text + prev, i - prev); + empathy_string_parser_substr (string, text + prev, + i - prev, user_data); g_string_append (string, "<br/>"); prev = i + 1; } } - theme_adium_parser_escape (string, text + prev, i - prev); + empathy_string_parser_substr (string, text + prev, i - prev, user_data); } static void theme_adium_parser_smiley (GString *string, const gchar *text, - gssize len) + gssize len, + gpointer user_data) { gboolean use_smileys = FALSE; gint last = 0; @@ -251,8 +255,9 @@ theme_adium_parser_smiley (GString *string, if (hit->start > last) { /* Append the text between last smiley (or the * start of the message) and this smiley */ - theme_adium_parser_newline (string, text + last, - hit->start - last); + empathy_string_parser_substr (string, text + last, + hit->start - last, + user_data); } /* Replace smileys by a <img/> tag */ @@ -273,13 +278,14 @@ theme_adium_parser_smiley (GString *string, g_object_unref (smiley_manager); } - theme_adium_parser_newline (string, text + last, len - last); + empathy_string_parser_substr (string, text + last, len - last, user_data); } static void theme_adium_parser_url (GString *string, const gchar *text, - gssize len) + gssize len, + gpointer user_data) { GRegex *uri_regex; GMatchInfo *match_info; @@ -300,8 +306,9 @@ theme_adium_parser_url (GString *string, if (s > last) { /* Append the text between last link (or the * start of the message) and this link */ - theme_adium_parser_smiley (string, text + last, - s - last); + empathy_string_parser_substr (string, text + last, + s - last, + user_data); } /* Append the link inside <a href=""></a> tag */ @@ -317,12 +324,20 @@ theme_adium_parser_url (GString *string, } while (g_match_info_next (match_info, NULL)); } - theme_adium_parser_smiley (string, text + last, len - last); + 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, + theme_adium_parser_smiley, + theme_adium_parser_newline, + theme_adium_parser_escape, + NULL, +}; + static gchar * theme_adium_parse_body (const gchar *text) { @@ -343,7 +358,7 @@ theme_adium_parse_body (const gchar *text) */ string = g_string_sized_new (strlen (text)); - theme_adium_parser_url (string, text, -1); + empathy_string_parser_substr (string, text, -1, string_parsers); return g_string_free (string, FALSE); } |