Code

data: Let sdb_data_parse() support inline casts from string to other types.
[sysdb.git] / src / include / core / data.h
index a81cea45b5b6e5f52d5c6ba671f5b2ae42aa1e3c..ffddf979f5509593417c80d6b3358b0b75e27a34 100644 (file)
@@ -46,7 +46,7 @@ enum {
        SDB_TYPE_STRING,
        SDB_TYPE_DATETIME,
        SDB_TYPE_BINARY,
-       SDB_TYPE_REGEX,
+       SDB_TYPE_REGEX, /* extended, case-insensitive POSIX regex */
 };
 
 #define SDB_TYPE_TO_STRING(t) \
@@ -153,18 +153,24 @@ enum {
 };
 
 #define SDB_DATA_OP_TO_STRING(op) \
-       (((op) == SDB_DATA_ADD) \
-               ? "+" \
-               : ((op) == SDB_DATA_SUB) \
-                       ? "-" \
-                       : ((op) == SDB_DATA_MUL) \
-                               ? "*" \
-                               : ((op) == SDB_DATA_DIV) \
-                                       ? "/" \
-                                       : ((op) == SDB_DATA_MOD) \
-                                               ? "%" \
-                                               : ((op) == SDB_DATA_CONCAT) \
-                                                       ? "||" : "UNKNOWN")
+       (((op) == SDB_DATA_ADD) ? "+" \
+               : ((op) == SDB_DATA_SUB) ? "-" \
+               : ((op) == SDB_DATA_MUL) ? "*" \
+               : ((op) == SDB_DATA_DIV) ? "/" \
+               : ((op) == SDB_DATA_MOD) ? "%" \
+               : ((op) == SDB_DATA_CONCAT) ? "||" : "UNKNOWN")
+
+/*
+ * sdb_data_parse_op:
+ * Parse the string representation of an operator supported by
+ * sdb_data_expr_eval.
+ *
+ * Returns:
+ *  - the ID of the operator
+ *  - a negative value in case the operator does not exist
+ */
+int
+sdb_data_parse_op(const char *op);
 
 /*
  * sdb_data_expr_eval:
@@ -233,6 +239,11 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted);
  * memory and also compiled to a regex. Use sdb_data_free_datum() to free the
  * dynamically allocated memory.
  *
+ * The input string may be stored in 'data', that is, the function may be used
+ * to do an inline cast from a string to any other type. It is the callers
+ * responsibility to free the memory used by the string in case the target
+ * type does not keep a reference to it.
+ *
  * Returns:
  *  - 0 on success
  *  - a negative value else