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

Function eval_comparison_op

src/cypher/cypher.c:2686–2733  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2684
2685/* Evaluate a comparison operator between actual and expected strings. */
2686static bool eval_comparison_op(const char *op, const char *actual, const char *expected) {
2687 if (strcmp(op, "=") == 0) {
2688 return strcmp(actual, expected) == 0;
2689 }
2690 if (strcmp(op, "<>") == 0) {
2691 return strcmp(actual, expected) != 0;
2692 }
2693 if (strcmp(op, "=~") == 0) {
2694 cbm_regex_t re;
2695 int comp_rc = cbm_regcomp(&re, expected, CBM_REG_EXTENDED | CBM_REG_NOSUB);
2696 if (comp_rc != 0) {
2697 if (comp_rc == CBM_REG_ETOOBIG) {
2698 g_cypher_regex_refused = true;
2699 }
2700 return false;
2701 }
2702 int rc = cbm_regexec(&re, actual, 0, NULL, 0);
2703 cbm_regfree(&re);
2704 return rc == 0;
2705 }
2706 if (strcmp(op, "CONTAINS") == 0) {
2707 return strstr(actual, expected) != NULL;
2708 }
2709 if (strcmp(op, "STARTS WITH") == 0) {
2710 return strncmp(actual, expected, strlen(expected)) == 0;
2711 }
2712 if (strcmp(op, "ENDS WITH") == 0) {
2713 size_t alen = strlen(actual);
2714 size_t elen = strlen(expected);
2715 return alen >= elen && strcmp(actual + alen - elen, expected) == 0;
2716 }
2717 if (strcmp(op, ">") == 0 || strcmp(op, "<") == 0 || strcmp(op, ">=") == 0 ||
2718 strcmp(op, "<=") == 0) {
2719 double a = strtod(actual, NULL);
2720 double exp_val = strtod(expected, NULL);
2721 if (op[0] == '>' && op[CYP_CHAR_IDX1] == '=') {
2722 return a >= exp_val;
2723 }
2724 if (op[0] == '<' && op[CYP_CHAR_IDX1] == '=') {
2725 return a <= exp_val;
2726 }
2727 if (op[0] == '>') {
2728 return a > exp_val;
2729 }
2730 return a < exp_val;
2731 }
2732 return false;
2733}
2734
2735/* Evaluate a WHERE condition against a binding */
2736static 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