No issues found
1 /*
2 * Copyright (C) 2011 Nokia <ivan.frade@nokia.com>
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
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #include <glib.h>
23 #include "tracker-encoding-enca.h"
24
25 #include <enca.h>
26
27 gchar *
28 tracker_encoding_guess_enca (const gchar *buffer,
29 gsize size)
30 {
31 gchar *encoding = NULL;
32 const gchar **langs;
33 gsize s;
34 gsize i;
35
36 langs = enca_get_languages (&s);
37
38 for (i = 0; i < s && !encoding; i++) {
39 EncaAnalyser analyser;
40 EncaEncoding eencoding;
41
42 analyser = enca_analyser_alloc (langs[i]);
43 eencoding = enca_analyse_const (analyser, (guchar *)buffer, size);
44
45 if (enca_charset_is_known (eencoding.charset)) {
46 encoding = g_strdup (enca_charset_name (eencoding.charset,
47 ENCA_NAME_STYLE_ICONV));
48 }
49
50 enca_analyser_free (analyser);
51 }
52
53 free (langs);
54
55 if (encoding)
56 g_debug ("Guessing charset as '%s'", encoding);
57
58 return encoding;
59 }