[evolution-data-server] EBookBackendSexp: Support regex query types.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] EBookBackendSexp: Support regex query types.
- Date: Thu, 30 May 2013 12:05:47 +0000 (UTC)
commit c212819f0676f4e262eee757548852d574fa129d
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Tue Apr 23 17:35:54 2013 +0900
EBookBackendSexp: Support regex query types.
addressbook/libedata-book/e-book-backend-sexp.c | 75 +++++++++++++++++++++++
po/POTFILES.in | 1 +
2 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sexp.c b/addressbook/libedata-book/e-book-backend-sexp.c
index 3cd220f..0b8a8fc 100644
--- a/addressbook/libedata-book/e-book-backend-sexp.c
+++ b/addressbook/libedata-book/e-book-backend-sexp.c
@@ -20,6 +20,7 @@
#include "e-book-backend-sexp.h"
+#include <glib/gi18n.h>
#include <locale.h>
#include <string.h>
@@ -850,6 +851,78 @@ func_eqphone_short (struct _ESExp *f,
}
static gboolean
+regex_helper (const gchar *ps1,
+ const gchar *ps2,
+ const gchar *region,
+ gboolean normalize)
+{
+ const gchar *field_data = ps1;
+ const gchar *expression = ps2;
+ GRegex *regex;
+ GError *error = NULL;
+ gboolean match = FALSE;
+
+ regex = g_regex_new (expression, 0, 0, &error);
+ if (!regex) {
+ g_warning ("Failed to parse regular expression '%s': %s",
+ expression, error ? error->message : _("Unknown error"));
+ g_clear_error (&error);
+ return FALSE;
+ }
+
+ if (normalize) {
+ gchar *normal = e_util_utf8_normalize (field_data);
+
+ match = g_regex_match (regex, normal, 0, NULL);
+
+ g_free (normal);
+ } else
+ match = g_regex_match (regex, field_data, 0, NULL);
+
+ g_regex_unref (regex);
+
+ return match;
+}
+
+static gboolean
+regex_normal_helper (const gchar *ps1,
+ const gchar *ps2,
+ const gchar *region)
+{
+ return regex_helper (ps1, ps2, region, TRUE);
+}
+
+static gboolean
+regex_raw_helper (const gchar *ps1,
+ const gchar *ps2,
+ const gchar *region)
+{
+ return regex_helper (ps1, ps2, region, FALSE);
+}
+
+static ESExpResult *
+func_regex_normal (struct _ESExp *f,
+ gint argc,
+ struct _ESExpResult **argv,
+ gpointer data)
+{
+ SearchContext *ctx = data;
+
+ return entry_compare (ctx, f, argc, argv, regex_normal_helper);
+}
+
+static ESExpResult *
+func_regex_raw (struct _ESExp *f,
+ gint argc,
+ struct _ESExpResult **argv,
+ gpointer data)
+{
+ SearchContext *ctx = data;
+
+ return entry_compare (ctx, f, argc, argv, regex_raw_helper);
+}
+
+static gboolean
exists_helper (const gchar *ps1,
const gchar *ps2,
const gchar *region)
@@ -1037,6 +1110,8 @@ static struct {
{ "eqphone", func_eqphone, 0 },
{ "eqphone_national", func_eqphone_national, 0 },
{ "eqphone_short", func_eqphone_short, 0 },
+ { "regex_normal", func_regex_normal, 0 },
+ { "regex_raw", func_regex_raw, 0 },
{ "exists", func_exists, 0 },
{ "exists_vcard", func_exists_vcard, 0 },
};
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4af316e..5ee0de3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,6 +15,7 @@ addressbook/libebook/e-book-client.c
addressbook/libebook/e-book-client-view.c
addressbook/libebook/e-destination.c
addressbook/libedata-book/e-book-backend.c
+addressbook/libedata-book/e-book-backend-sexp.c
addressbook/libedata-book/e-book-backend-sqlitedb.c
addressbook/libedata-book/e-data-book.c
addressbook/libedata-book/e-data-book-factory.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]