MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / eval_comparison_op

Function eval_comparison_op

src/cypher/cypher.c:2578–2621  ·  view source on GitHub ↗

Evaluate a comparison operator between actual and expected strings. */

Source from the content-addressed store, hash-verified

2576
2577/* Evaluate a comparison operator between actual and expected strings. */
2578static bool eval_comparison_op(const char *op, const char *actual, const char *expected) {
2579 if (strcmp(op, "=") == 0) {
2580 return strcmp(actual, expected) == 0;
2581 }
2582 if (strcmp(op, "<>") == 0) {
2583 return strcmp(actual, expected) != 0;
2584 }
2585 if (strcmp(op, "=~") == 0) {
2586 cbm_regex_t re;
2587 if (cbm_regcomp(&re, expected, CBM_REG_EXTENDED | CBM_REG_NOSUB) != 0) {
2588 return false;
2589 }
2590 int rc = cbm_regexec(&re, actual, 0, NULL, 0);
2591 cbm_regfree(&re);
2592 return rc == 0;
2593 }
2594 if (strcmp(op, "CONTAINS") == 0) {
2595 return strstr(actual, expected) != NULL;
2596 }
2597 if (strcmp(op, "STARTS WITH") == 0) {
2598 return strncmp(actual, expected, strlen(expected)) == 0;
2599 }
2600 if (strcmp(op, "ENDS WITH") == 0) {
2601 size_t alen = strlen(actual);
2602 size_t elen = strlen(expected);
2603 return alen >= elen && strcmp(actual + alen - elen, expected) == 0;
2604 }
2605 if (strcmp(op, ">") == 0 || strcmp(op, "<") == 0 || strcmp(op, ">=") == 0 ||
2606 strcmp(op, "<=") == 0) {
2607 double a = strtod(actual, NULL);
2608 double exp_val = strtod(expected, NULL);
2609 if (op[0] == '>' && op[CYP_CHAR_IDX1] == '=') {
2610 return a >= exp_val;
2611 }
2612 if (op[0] == '<' && op[CYP_CHAR_IDX1] == '=') {
2613 return a <= exp_val;
2614 }
2615 if (op[0] == '>') {
2616 return a > exp_val;
2617 }
2618 return a < exp_val;
2619 }
2620 return false;
2621}
2622
2623/* Evaluate a WHERE condition against a binding */
2624static bool eval_condition(const cbm_condition_t *c, binding_t *b) {

Callers 1

eval_conditionFunction · 0.85

Calls 3

cbm_regcompFunction · 0.85
cbm_regexecFunction · 0.85
cbm_regfreeFunction · 0.85

Tested by

no test coverage detected