[tracker/meegotouch-guess-charset: 3/5] libtracker-common: move enca encoding detector to separate files
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/meegotouch-guess-charset: 3/5] libtracker-common: move enca encoding detector to separate files
- Date: Fri, 25 Feb 2011 14:20:34 +0000 (UTC)
commit 86b16a021d502f44be94484fc628c8708c3fbc2d
Author: Aleksander Morgado <aleksander lanedo com>
Date: Fri Feb 25 12:10:57 2011 +0100
libtracker-common: move enca encoding detector to separate files
src/libtracker-common/Makefile.am | 5 ++
src/libtracker-common/tracker-encoding-enca.c | 56 +++++++++++++++++++++++++
src/libtracker-common/tracker-encoding-enca.h | 33 ++++++++++++++
src/libtracker-common/tracker-encoding.c | 36 +---------------
4 files changed, 96 insertions(+), 34 deletions(-)
---
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index 9f05a61..a77387d 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -48,6 +48,11 @@ noinst_HEADERS = \
tracker-locale.h \
tracker-encoding.h
+if HAVE_ENCA
+libtracker_common_la_SOURCES += tracker-encoding-enca.c
+noinst_HEADERS += tracker-encoding-enca.h
+endif
+
if HAVE_TRACKER_FTS
libtracker_common_la_SOURCES += tracker-language.c
noinst_HEADERS += tracker-language.h
diff --git a/src/libtracker-common/tracker-encoding-enca.c b/src/libtracker-common/tracker-encoding-enca.c
new file mode 100644
index 0000000..1b034ff
--- /dev/null
+++ b/src/libtracker-common/tracker-encoding-enca.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2011 Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include "tracker-encoding-enca.h"
+
+#include <enca.h>
+
+gchar *
+tracker_encoding_guess_enca (const gchar *buffer,
+ gsize size)
+{
+ gchar *encoding = NULL;
+ const gchar **langs;
+ gsize s;
+ gsize i;
+
+ langs = enca_get_languages (&s);
+
+ for (i = 0; i < s && !encoding; i++) {
+ EncaAnalyser analyser;
+ EncaEncoding eencoding;
+
+ analyser = enca_analyser_alloc (langs[i]);
+ eencoding = enca_analyse_const (analyser, (guchar *)buffer, size);
+
+ if (enca_charset_is_known (eencoding.charset)) {
+ encoding = g_strdup (enca_charset_name (eencoding.charset,
+ ENCA_NAME_STYLE_ICONV));
+ }
+
+ enca_analyser_free (analyser);
+ }
+
+ free (langs);
+
+ return encoding;
+}
diff --git a/src/libtracker-common/tracker-encoding-enca.h b/src/libtracker-common/tracker-encoding-enca.h
new file mode 100644
index 0000000..6a00c2b
--- /dev/null
+++ b/src/libtracker-common/tracker-encoding-enca.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_COMMON_ENCODING_ENCA_H__
+#define __LIBTRACKER_COMMON_ENCODING_ENCA_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL
+gchar *tracker_encoding_guess_enca (const gchar *buffer,
+ gsize size);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_COMMON_ENCODING_ENCA_H__ */
diff --git a/src/libtracker-common/tracker-encoding.c b/src/libtracker-common/tracker-encoding.c
index 6868d1b..9a9ee07 100644
--- a/src/libtracker-common/tracker-encoding.c
+++ b/src/libtracker-common/tracker-encoding.c
@@ -23,41 +23,9 @@
#include "tracker-encoding.h"
#ifdef HAVE_ENCA
-#include <enca.h>
+#include <tracker-encoding-enca.h>
#endif
-#ifdef HAVE_ENCA
-static gchar *
-encoding_guess_enca (const gchar *buffer,
- gsize size)
-{
- gchar *encoding = NULL;
- const gchar **langs;
- gsize s;
- gsize i;
-
- langs = enca_get_languages (&s);
-
- for (i = 0; i < s && !encoding; i++) {
- EncaAnalyser analyser;
- EncaEncoding eencoding;
-
- analyser = enca_analyser_alloc (langs[i]);
- eencoding = enca_analyse_const (analyser, buffer, size);
-
- if (enca_charset_is_known (eencoding.charset)) {
- encoding = g_strdup (enca_charset_name (eencoding.charset,
- ENCA_NAME_STYLE_ICONV));
- }
-
- enca_analyser_free (analyser);
- }
-
- free (langs);
-
- return encoding;
-}
-#endif /* HAVE_ENCA */
gboolean
tracker_encoding_can_guess (void)
@@ -77,7 +45,7 @@ tracker_encoding_guess (const gchar *buffer,
#ifdef HAVE_ENCA
if (!encoding)
- encoding = encoding_guess_enca (buffer, size);
+ encoding = tracker_encoding_guess_enca (buffer, size);
#endif /* HAVE_ENCA */
return encoding;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]