summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2a5dbbf)
raw | patch | inline | side by side (parent: 2a5dbbf)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 21 Oct 2014 05:36:41 +0000 (07:36 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 21 Oct 2014 05:36:41 +0000 (07:36 +0200) |
This function creates a matcher which matches if the right value evaluates to
an array value and the left value is included in that array.
an array value and the left value is included in that array.
src/core/store-private.h | patch | blob | history | |
src/core/store_lookup.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history |
index 3db771bc070ddbc5382128aea1ea3558642824dd..750a0b32bbb4e83706f5ac7658e25cf8e48904bf 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
MATCHER_CMP_NE,
MATCHER_CMP_GE,
MATCHER_CMP_GT,
+ MATCHER_IN,
MATCHER_REGEX,
MATCHER_NREGEX,
MATCHER_ISNULL,
: ((t) == MATCHER_CMP_NE) ? "!=" \
: ((t) == MATCHER_GE) ? ">=" \
: ((t) == MATCHER_GT) ? ">" \
+ : ((t) == MATCHER_IN) ? "IN" \
: ((t) == MATCHER_REGEX) ? "=~" \
: ((t) == MATCHER_NREGEX) ? "!~" \
: ((t) == MATCHER_ISNULL) ? "IS NULL" \
index 21e0ba4ef4dd13d30d1fcfe7d9bf6c9a0465fafa..274ca027421d1540563c8d4dfdccab15c077384c 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
return (status != INT_MAX) && (status > 0);
} /* match_cmp_gt */
+static int
+match_in(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
+ sdb_store_matcher_t *filter)
+{
+ sdb_data_t value = SDB_DATA_INIT, array = SDB_DATA_INIT;
+ int status = 1;
+
+ assert(m->type == MATCHER_IN);
+
+ if ((sdb_store_expr_eval(CMP_M(m)->left, obj, &value, filter))
+ || (sdb_store_expr_eval(CMP_M(m)->right, obj, &array, filter)))
+ status = 0;
+
+ if (status)
+ status = sdb_data_inarray(&value, &array);
+
+ sdb_data_free_datum(&value);
+ sdb_data_free_datum(&array);
+ return status;
+} /* match_in */
+
static int
match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
sdb_store_matcher_t *filter)
match_cmp_ne,
match_cmp_ge,
match_cmp_gt,
+ match_in,
match_regex,
match_regex,
match_isnull,
cmp_tostring,
cmp_tostring,
cmp_tostring,
+ cmp_tostring,
isnull_tostring,
isnull_tostring,
};
MATCHER_CMP_GT, left, right));
} /* sdb_store_cmp_gt */
+sdb_store_matcher_t *
+sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+{
+ return M(sdb_object_create("in-matcher", cmp_type,
+ MATCHER_IN, left, right));
+} /* sdb_store_in_matcher */
+
sdb_store_matcher_t *
sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
{
index b1d15f5b77d7569e771ddd5bc5ae8741ae5f229e..2e1e558a87fbc11a2c983261b83235b8448c0129 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
sdb_store_matcher_t *
sdb_store_cmp_gt(sdb_store_expr_t *left, sdb_store_expr_t *right);
+/*
+ * sdb_store_in_matcher:
+ * Creates a matcher which matches if the right value evaluates to an array
+ * value and the left value is included in that array. See sdb_data_inarray
+ * for more details.
+ */
+sdb_store_matcher_t *
+sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
+
/*
* sdb_store_regex_matcher:
* Creates a matcher which matches the string value the left expression