2 * Copyright (C) 2008-2009 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Xavier Claessens <xclaesse@gmail.com>
21 #include "empathy-webkit-utils.h"
22 #include "empathy-smiley-manager.h"
25 empathy_webkit_match_newline (const gchar *text,
27 EmpathyStringReplace replace_func,
28 EmpathyStringParser *sub_parsers,
31 GString *string = user_data;
38 /* Replace \n by <br/> */
39 for (i = 0; i < len && text[i] != '\0'; i++)
43 empathy_string_parser_substr (text + prev, i - prev,
44 sub_parsers, user_data);
45 g_string_append (string, "<br/>");
50 empathy_string_parser_substr (text + prev, i - prev,
51 sub_parsers, user_data);
55 empathy_webkit_replace_smiley (const gchar *text,
60 EmpathySmileyHit *hit = match_data;
61 GString *string = user_data;
63 /* Replace smiley by a <img/> tag */
64 g_string_append_printf (string,
65 "<img src=\"%s\" alt=\"%.*s\" title=\"%.*s\"/>",
66 hit->path, (int)len, text, (int)len, text);
69 static EmpathyStringParser string_parsers[] = {
70 { empathy_string_match_link, empathy_string_replace_link },
71 { empathy_webkit_match_newline, NULL },
72 { empathy_string_match_all, empathy_string_replace_escaped },
76 static EmpathyStringParser string_parsers_with_smiley[] = {
77 { empathy_string_match_link, empathy_string_replace_link },
78 { empathy_string_match_smiley, empathy_webkit_replace_smiley },
79 { empathy_webkit_match_newline, NULL },
80 { empathy_string_match_all, empathy_string_replace_escaped },
85 empathy_webkit_get_string_parser (gboolean smileys)
88 return string_parsers_with_smiley;
90 return string_parsers;