[evolution-data-server/openismus-work-3-8: 100/118] EBookBackendSexp: Support new transliterated query types.



commit 569d94cee4d52d2ee6ff159974aa405b3d353365
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Tue Aug 27 13:49:08 2013 +0200

    EBookBackendSexp: Support new transliterated query types.

 addressbook/libedata-book/e-book-backend-sexp.c |  139 +++++++++++++++++++++++
 1 files changed, 139 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sexp.c b/addressbook/libedata-book/e-book-backend-sexp.c
index 57956fd..90b4d93 100644
--- a/addressbook/libedata-book/e-book-backend-sexp.c
+++ b/addressbook/libedata-book/e-book-backend-sexp.c
@@ -1062,6 +1062,141 @@ func_exists_vcard (struct _ESExp *f,
        return r;
 }
 
+/* first space between words is treated as wildcard character;
+ * we are looking for s2 in s1, so s2 will be breaked into words
+ */
+static gboolean
+translit_contains_helper (const gchar *s1,
+                         const gchar *s2,
+                         const gchar *region)
+{
+       ETransliterator *transliterator;
+       gchar *t1, *t2;
+       gboolean res = FALSE;
+
+       transliterator = e_transliterator_new ("Any-Latin");
+       t1 = e_transliterator_transliterate (transliterator, s1);
+       t2 = e_transliterator_transliterate (transliterator, s2);
+       e_transliterator_unref (transliterator);
+
+       res = contains_helper (t1, t2, region);
+
+       g_free (t1);
+       g_free (t2);
+
+       return res;
+}
+
+static ESExpResult *
+func_translit_contains (struct _ESExp *f,
+                       gint argc,
+                       struct _ESExpResult **argv,
+                       gpointer data)
+{
+       SearchContext *ctx = data;
+
+       return entry_compare (ctx, f, argc, argv, translit_contains_helper);
+}
+
+static gboolean
+translit_is_helper (const gchar *ps1,
+                   const gchar *ps2,
+                   const gchar *region)
+{
+       ETransliterator *transliterator;
+       gchar *t1, *t2;
+       gboolean res = FALSE;
+
+       transliterator = e_transliterator_new ("Any-Latin");
+       t1 = e_transliterator_transliterate (transliterator, ps1);
+       t2 = e_transliterator_transliterate (transliterator, ps2);
+       e_transliterator_unref (transliterator);
+
+       res = is_helper (t1, t2, region);
+
+       g_free (t1);
+       g_free (t2);
+
+       return res;
+}
+
+static ESExpResult *
+func_translit_is (struct _ESExp *f,
+                 gint argc,
+                 struct _ESExpResult **argv,
+                 gpointer data)
+{
+       SearchContext *ctx = data;
+
+       return entry_compare (ctx, f, argc, argv, translit_is_helper);
+}
+
+static gboolean
+translit_endswith_helper (const gchar *ps1,
+                         const gchar *ps2,
+                         const gchar *region)
+{
+       ETransliterator *transliterator;
+       gchar *t1, *t2;
+       gboolean res = FALSE;
+
+       transliterator = e_transliterator_new ("Any-Latin");
+       t1 = e_transliterator_transliterate (transliterator, ps1);
+       t2 = e_transliterator_transliterate (transliterator, ps2);
+       e_transliterator_unref (transliterator);
+
+       res = endswith_helper (t1, t2, region);
+
+       g_free (t1);
+       g_free (t2);
+
+       return res;
+}
+
+static ESExpResult *
+func_translit_endswith (struct _ESExp *f,
+                       gint argc,
+                       struct _ESExpResult **argv,
+                       gpointer data)
+{
+       SearchContext *ctx = data;
+
+       return entry_compare (ctx, f, argc, argv, translit_endswith_helper);
+}
+
+static gboolean
+translit_beginswith_helper (const gchar *ps1,
+                           const gchar *ps2,
+                           const gchar *region)
+{
+       ETransliterator *transliterator;
+       gchar *t1, *t2;
+       gboolean res = FALSE;
+
+       transliterator = e_transliterator_new ("Any-Latin");
+       t1 = e_transliterator_transliterate (transliterator, ps1);
+       t2 = e_transliterator_transliterate (transliterator, ps2);
+       e_transliterator_unref (transliterator);
+
+       res = beginswith_helper (t1, t2, region);
+
+       g_free (t1);
+       g_free (t2);
+
+       return res;
+}
+
+static ESExpResult *
+func_translit_beginswith (struct _ESExp *f,
+                         gint argc,
+                         struct _ESExpResult **argv,
+                         gpointer data)
+{
+       SearchContext *ctx = data;
+
+       return entry_compare (ctx, f, argc, argv, translit_beginswith_helper);
+}
+
 static void
 book_backend_sexp_finalize (GObject *object)
 {
@@ -1113,6 +1248,10 @@ static struct {
        { "regex_raw", func_regex_raw, 0 },
        { "exists", func_exists, 0 },
        { "exists_vcard", func_exists_vcard, 0 },
+       { "translit_contains", func_translit_contains, 0 },
+       { "translit_is", func_translit_is, 0 },
+       { "translit_beginswith", func_translit_beginswith, 0 },
+       { "translit_endswith", func_translit_endswith, 0 },
 };
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]