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

Function eval_multiarg_func

src/cypher/cypher.c:4167–4248  ·  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

4165
4166/* Evaluate a multi-argument scalar function into func_buf (or a direct value). */
4167static const char *eval_multiarg_func(binding_t *b, const cbm_return_item_t *item, char *buf,
4168 size_t bufsz) {
4169 const char *f = item->func;
4170 int n = item->arg_count;
4171 if (strcmp(f, "coalesce") == 0) {
4172 for (int i = 0; i < n; i++) {
4173 const char *v = eval_func_arg(b, &item->args[i]);
4174 if (v && v[0]) {
4175 return v;
4176 }
4177 }
4178 return "";
4179 }
4180 if (strcmp(f, "substring") == 0 && n >= 2) {
4181 const char *s = eval_func_arg(b, &item->args[0]);
4182 long start = strtol(eval_func_arg(b, &item->args[1]), NULL, CBM_DECIMAL_BASE);
4183 size_t slen = strlen(s);
4184 if (start < 0 || (size_t)start >= slen) {
4185 return "";
4186 }
4187 size_t take = slen - (size_t)start;
4188 if (n >= 3) {
4189 long len = strtol(eval_func_arg(b, &item->args[2]), NULL, CBM_DECIMAL_BASE);
4190 if (len < 0) {
4191 len = 0;
4192 }
4193 if ((size_t)len < take) {
4194 take = (size_t)len;
4195 }
4196 }
4197 if (take >= bufsz) {
4198 take = bufsz - SKIP_ONE;
4199 }
4200 memcpy(buf, s + start, take);
4201 buf[take] = '\0';
4202 return buf;
4203 }
4204 if ((strcmp(f, "left") == 0 || strcmp(f, "right") == 0) && n >= 2) {
4205 const char *s = eval_func_arg(b, &item->args[0]);
4206 long k = strtol(eval_func_arg(b, &item->args[1]), NULL, CBM_DECIMAL_BASE);
4207 if (k < 0) {
4208 k = 0;
4209 }
4210 size_t slen = strlen(s);
4211 size_t take = (size_t)k < slen ? (size_t)k : slen;
4212 if (take >= bufsz) {
4213 take = bufsz - SKIP_ONE;
4214 }
4215 memcpy(buf, (strcmp(f, "left") == 0) ? s : s + (slen - take), take);
4216 buf[take] = '\0';
4217 return buf;
4218 }
4219 if (strcmp(f, "replace") == 0 && n >= 3) {
4220 const char *s = eval_func_arg(b, &item->args[0]);
4221 const char *from = eval_func_arg(b, &item->args[1]);
4222 const char *to = eval_func_arg(b, &item->args[2]);
4223 size_t fromlen = strlen(from);
4224 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