[evolution-data-server/openismus-work-master: 45/83] Added ETransliteratorPrivate C++ Glue
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 45/83] Added ETransliteratorPrivate C++ Glue
- Date: Fri, 4 Oct 2013 19:16:15 +0000 (UTC)
commit 7e32b0b99509d3c11ffd49d19d5e5a80e51bc591
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Jun 8 20:13:23 2013 +0900
Added ETransliteratorPrivate C++ Glue
Added this glue to call icu::Transliterator C++ APIs on behalf
of ECollator.
libedataserver/Makefile.am | 9 ++-
libedataserver/e-transliterator-private.cpp | 92 +++++++++++++++++++++++++++
libedataserver/e-transliterator-private.h | 56 ++++++++++++++++
3 files changed, 153 insertions(+), 4 deletions(-)
---
diff --git a/libedataserver/Makefile.am b/libedataserver/Makefile.am
index 156f7a1..a016e6c 100644
--- a/libedataserver/Makefile.am
+++ b/libedataserver/Makefile.am
@@ -16,7 +16,7 @@ ENUM_GENERATED = e-source-enumtypes.h e-source-enumtypes.c
BUILT_SOURCES = $(ENUM_GENERATED)
lib_LTLIBRARIES = libedataserver-1.2.la
-noinst_LTLIBRARIES = libealphabetindex-private.la
+noinst_LTLIBRARIES = libedataserver-private.la
libedataserver_1_2_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
@@ -90,6 +90,7 @@ libedataserver_1_2_la_SOURCES = \
e-source-webdav.c \
e-debug-log.c \
e-time-utils.c \
+ e-transliterator-private.h \
e-uid.c \
e-url.c \
e-data-server-util.c \
@@ -176,9 +177,9 @@ libedataserverinclude_HEADERS = \
# We put the C++ code into a separate static library, so that we can use
# the C linker for libebook-contacts.
-libealphabetindex_private_la_SOURCES = e-alphabet-index-private.cpp
-libealphabetindex_private_la_CPPFLAGS = $(libedataserver_1_2_la_CPPFLAGS)
-libedataserver_1_2_la_LIBADD += @predeps_CXX@ libealphabetindex-private.la @postdeps_CXX@
+libedataserver_private_la_SOURCES = e-alphabet-index-private.cpp e-transliterator-private.cpp
+libedataserver_private_la_CPPFLAGS = $(libedataserver_1_2_la_CPPFLAGS)
+libedataserver_1_2_la_LIBADD += @predeps_CXX@ libedataserver-private.la @postdeps_CXX@
%-$(API_VERSION).pc: %.pc
cp $< $@
diff --git a/libedataserver/e-transliterator-private.cpp b/libedataserver/e-transliterator-private.cpp
new file mode 100644
index 0000000..9e6b4a4
--- /dev/null
+++ b/libedataserver/e-transliterator-private.cpp
@@ -0,0 +1,92 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-transliterator-private.h"
+
+/* C++ standard library */
+#include <string>
+#include <memory>
+
+/* system headers */
+#include <langinfo.h>
+#include <locale.h>
+
+/* ICU headers */
+#include <unicode/translit.h>
+
+using icu::Transliterator;
+
+struct _ETransliterator {
+ Transliterator *priv;
+};
+
+/* Create an Transliterator for the source and target
+ * language stripts
+ */
+ETransliterator *
+_e_transliterator_cxx_new (const gchar *transliterator_id)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ ETransliterator *transliterator;
+
+ g_return_val_if_fail (transliterator_id != NULL, NULL);
+
+ transliterator = g_slice_new (ETransliterator);
+ transliterator->priv = Transliterator::createInstance (transliterator_id, UTRANS_FORWARD, status);
+
+ return transliterator;
+}
+
+/* Frees an ETransliterator and it's associated resources
+ */
+void
+_e_transliterator_cxx_free (ETransliterator *transliterator)
+{
+ if (transliterator) {
+ delete transliterator->priv;
+ g_slice_free (ETransliterator, transliterator);
+ }
+}
+
+/* Transliterates 'str' and returns the new allocated result
+ */
+gchar *
+_e_transliterator_cxx_transliterate (ETransliterator *transliterator,
+ const gchar *str)
+{
+ UnicodeString transform;
+ std::string sourceUTF8;
+ std::string targetUTF8;
+
+ g_return_val_if_fail (transliterator != NULL, NULL);
+ g_return_val_if_fail (str != NULL, NULL);
+
+ sourceUTF8 = str;
+ transform = icu::UnicodeString::fromUTF8 (sourceUTF8);
+ transliterator->priv->transliterate (transform);
+ targetUTF8 = transform.toUTF8String (targetUTF8);
+
+ return g_strdup (targetUTF8.c_str());
+}
diff --git a/libedataserver/e-transliterator-private.h b/libedataserver/e-transliterator-private.h
new file mode 100644
index 0000000..539f0c1
--- /dev/null
+++ b/libedataserver/e-transliterator-private.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+#if !defined (__LIBEDATASERVER_H_INSIDE__) && !defined (LIBEDATASERVER_COMPILATION)
+#error "Only <libedataserver/libedataserver.h> should be included directly."
+#endif
+
+#ifndef E_TRANSLITERATOR_PRIVATE_H
+#define E_TRANSLITERATOR_PRIVATE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#if __GNUC__ >= 4
+# define E_TRANSLITERATOR_LOCAL __attribute__ ((visibility ("hidden")))
+#else
+# define E_TRANSLITERATOR_LOCAL
+#endif
+
+/**
+ * ETransliterator:
+ *
+ * A private opaque type describing an alphabetic index
+ *
+ * Since: 3.10
+ **/
+typedef struct _ETransliterator ETransliterator;
+
+/* defined in e-transliterator-private.cpp, and used by by e-collator.c */
+E_TRANSLITERATOR_LOCAL ETransliterator *_e_transliterator_cxx_new (const gchar
*transliterator_id);
+E_TRANSLITERATOR_LOCAL void _e_transliterator_cxx_free (ETransliterator
*transliterator);
+E_TRANSLITERATOR_LOCAL gchar *_e_transliterator_cxx_transliterate (ETransliterator
*transliterator,
+ const gchar *str);
+
+G_END_DECLS
+
+#endif /* E_TRANSLITERATOR_PRIVATE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]