Help: Use stable 'if' namespace instead of experimental
[empathy-mirror.git] / libempathy-gtk / empathy-string-parser.c
blobf17fc9c03dd961759027b5177fca5b00e4788398
1 /*
2 * Copyright (C) 2010 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 "config.h"
22 #include "empathy-string-parser.h"
24 #include "empathy-smiley-manager.h"
26 void
27 empathy_string_match_smiley (const gchar *text,
28 gssize len,
29 TpawStringReplace replace_func,
30 TpawStringParser *sub_parsers,
31 gpointer user_data)
33 guint last = 0;
34 EmpathySmileyManager *smiley_manager;
35 GSList *hits, *l;
37 smiley_manager = empathy_smiley_manager_dup_singleton ();
38 hits = empathy_smiley_manager_parse_len (smiley_manager, text, len);
40 for (l = hits; l; l = l->next) {
41 EmpathySmileyHit *hit = l->data;
43 if (hit->start > last) {
44 /* Append the text between last smiley (or the
45 * start of the message) and this smiley */
46 tpaw_string_parser_substr (text + last,
47 hit->start - last,
48 sub_parsers, user_data);
51 replace_func (text + hit->start, hit->end - hit->start,
52 hit, user_data);
54 last = hit->end;
56 empathy_smiley_hit_free (hit);
58 g_slist_free (hits);
59 g_object_unref (smiley_manager);
61 tpaw_string_parser_substr (text + last, len - last,
62 sub_parsers, user_data);