]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-string-parser.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy-gtk / empathy-string-parser.c
1 /*
2  * Copyright (C) 2010 Collabora Ltd.
3  *
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.
8  *
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.
13  *
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
17  *
18  * Authors: Xavier Claessens <xclaesse@gmail.com>
19  */
20
21 #include "config.h"
22 #include "empathy-string-parser.h"
23
24 #include "empathy-smiley-manager.h"
25
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)
32 {
33         guint last = 0;
34         EmpathySmileyManager *smiley_manager;
35         GSList *hits, *l;
36
37         smiley_manager = empathy_smiley_manager_dup_singleton ();
38         hits = empathy_smiley_manager_parse_len (smiley_manager, text, len);
39
40         for (l = hits; l; l = l->next) {
41                 EmpathySmileyHit *hit = l->data;
42
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);
49                 }
50
51                 replace_func (text + hit->start, hit->end - hit->start,
52                               hit, user_data);
53
54                 last = hit->end;
55
56                 empathy_smiley_hit_free (hit);
57         }
58         g_slist_free (hits);
59         g_object_unref (smiley_manager);
60
61         tpaw_string_parser_substr (text + last, len - last,
62                                    sub_parsers, user_data);
63 }