From: Sebastian Harl Date: Fri, 17 Oct 2014 06:36:42 +0000 (+0200) Subject: store: Added sdb_store_parse_matcher_op(). X-Git-Tag: sysdb-0.6.0~113 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2854b039898a32f1f4cc366dda97e3a3566529b3;p=sysdb.git store: Added sdb_store_parse_matcher_op(). This function parses the string representation of an operator and returns a constructor for the respective matcher. --- diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index cb3629c..325d67f 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -1242,6 +1242,28 @@ sdb_store_isnull_matcher(const char *attr_name) MATCHER_ISNULL, attr_name)); } /* sdb_store_isnull_matcher */ +sdb_store_matcher_op_cb +sdb_store_parse_matcher_op(const char *op) +{ + if (! strcasecmp(op, "<")) + return sdb_store_cmp_lt; + else if (! strcasecmp(op, "<=")) + return sdb_store_cmp_le; + else if (! strcasecmp(op, "=")) + return sdb_store_cmp_eq; + else if (! strcasecmp(op, "!=")) + return sdb_store_cmp_ne; + else if (! strcasecmp(op, ">=")) + return sdb_store_cmp_ge; + else if (! strcasecmp(op, ">")) + return sdb_store_cmp_gt; + else if (! strcasecmp(op, "=~")) + return sdb_store_regex_matcher; + else if (! strcasecmp(op, "!~")) + return sdb_store_nregex_matcher; + return NULL; +} /* sdb_store_parse_matcher_op */ + int sdb_store_parse_object_type_plural(const char *name) { diff --git a/src/include/core/store.h b/src/include/core/store.h index 5e57185..147d745 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -470,6 +470,25 @@ sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * sdb_store_nregex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); +/* + * sdb_store_matcher_op_cb: + * Callback constructing a matcher operator. + */ +typedef sdb_store_matcher_t *(*sdb_store_matcher_op_cb) + (sdb_store_expr_t *, sdb_store_expr_t *); + +/* + * sdb_store_parse_matcher_op: + * Parse a matcher operator and return a constructor for the respective + * matcher. + * + * Returns: + * - matcher operator constructor on success + * - NULL else + */ +sdb_store_matcher_op_cb +sdb_store_parse_matcher_op(const char *op); + /* * sdb_store_parse_object_type_plural: * Parse the type name (plural) of a stored object.