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

Function eval_multiarg_func

src/cypher/cypher.c:3568–3649  ·  view source on GitHub ↗

Evaluate a multi-argument scalar function into func_buf (or a direct value). */

Source from the content-addressed store, hash-verified

3566
3567/* Evaluate a multi-argument scalar function into func_buf (or a direct value). */
3568static const char *eval_multiarg_func(binding_t *b, const cbm_return_item_t *item, char *buf,
3569 size_t bufsz) {
3570 const char *f = item->func;
3571 int n = item->arg_count;
3572 if (strcmp(f, "coalesce") == 0) {
3573 for (int i = 0; i < n; i++) {
3574 const char *v = eval_func_arg(b, &item->args[i]);
3575 if (v && v[0]) {
3576 return v;
3577 }
3578 }
3579 return "";
3580 }
3581 if (strcmp(f, "substring") == 0 && n >= 2) {
3582 const char *s = eval_func_arg(b, &item->args[0]);
3583 long start = strtol(eval_func_arg(b, &item->args[1]), NULL, CBM_DECIMAL_BASE);
3584 size_t slen = strlen(s);
3585 if (start < 0 || (size_t)start >= slen) {
3586 return "";
3587 }
3588 size_t take = slen - (size_t)start;
3589 if (n >= 3) {
3590 long len = strtol(eval_func_arg(b, &item->args[2]), NULL, CBM_DECIMAL_BASE);
3591 if (len < 0) {
3592 len = 0;
3593 }
3594 if ((size_t)len < take) {
3595 take = (size_t)len;
3596 }
3597 }
3598 if (take >= bufsz) {
3599 take = bufsz - SKIP_ONE;
3600 }
3601 memcpy(buf, s + start, take);
3602 buf[take] = '\0';
3603 return buf;
3604 }
3605 if ((strcmp(f, "left") == 0 || strcmp(f, "right") == 0) && n >= 2) {
3606 const char *s = eval_func_arg(b, &item->args[0]);
3607 long k = strtol(eval_func_arg(b, &item->args[1]), NULL, CBM_DECIMAL_BASE);
3608 if (k < 0) {
3609 k = 0;
3610 }
3611 size_t slen = strlen(s);
3612 size_t take = (size_t)k < slen ? (size_t)k : slen;
3613 if (take >= bufsz) {
3614 take = bufsz - SKIP_ONE;
3615 }
3616 memcpy(buf, (strcmp(f, "left") == 0) ? s : s + (slen - take), take);
3617 buf[take] = '\0';
3618 return buf;
3619 }
3620 if (strcmp(f, "replace") == 0 && n >= 3) {
3621 const char *s = eval_func_arg(b, &item->args[0]);
3622 const char *from = eval_func_arg(b, &item->args[1]);
3623 const char *to = eval_func_arg(b, &item->args[2]);
3624 size_t fromlen = strlen(from);
3625 size_t tolen = strlen(to);

Callers 2

resolve_condition_valueFunction · 0.85
project_itemFunction · 0.85

Calls 1

eval_func_argFunction · 0.85

Tested by

no test coverage detected