[evolution-data-server/transliterated-queries: 3/5] EBookBackendSexp: Support new transliterated query types.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/transliterated-queries: 3/5] EBookBackendSexp: Support new transliterated query types.
- Date: Tue, 29 Oct 2013 16:23:49 +0000 (UTC)
commit 84f6e5be5a5fa4d9473657bae18352bf08e24aca
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Thu Oct 24 22:56:11 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 6bcd13f..61bb58c 100644
--- a/addressbook/libedata-book/e-book-backend-sexp.c
+++ b/addressbook/libedata-book/e-book-backend-sexp.c
@@ -1069,6 +1069,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)
{
@@ -1120,6 +1255,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]