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

Function apply_string_func

src/cypher/cypher.c:3276–3368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3274/* ── String function application ──────────────────────────────── */
3275
3276static const char *apply_string_func(const char *func, const char *val, char *buf, size_t buf_sz) {
3277 if (!func || !val) {
3278 return val ? val : "";
3279 }
3280 if (strcmp(func, "toLower") == 0) {
3281 size_t i = 0;
3282 for (; i < buf_sz - SKIP_ONE && val[i]; i++) {
3283 buf[i] = (char)tolower((unsigned char)val[i]);
3284 }
3285 buf[i] = '\0';
3286 return buf;
3287 }
3288 if (strcmp(func, "toUpper") == 0) {
3289 size_t i = 0;
3290 for (; i < buf_sz - SKIP_ONE && val[i]; i++) {
3291 buf[i] = (char)toupper((unsigned char)val[i]);
3292 }
3293 buf[i] = '\0';
3294 return buf;
3295 }
3296 if (strcmp(func, "toString") == 0) {
3297 return val; /* already strings */
3298 }
3299 if (strcmp(func, "toInteger") == 0) {
3300 char *end = NULL;
3301 long long v = strtoll(val, &end, CBM_DECIMAL_BASE);
3302 if (end == val) {
3303 /* Not an integer literal — accept a float string and truncate. */
3304 char *fend = NULL;
3305 double d = strtod(val, &fend);
3306 if (fend == val) {
3307 return ""; /* non-numeric → null */
3308 }
3309 v = (long long)d;
3310 }
3311 snprintf(buf, buf_sz, "%lld", v);
3312 return buf;
3313 }
3314 if (strcmp(func, "toFloat") == 0) {
3315 char *end = NULL;
3316 double d = strtod(val, &end);
3317 if (end == val) {
3318 return ""; /* non-numeric → null */
3319 }
3320 snprintf(buf, buf_sz, "%g", d);
3321 return buf;
3322 }
3323 if (strcmp(func, "toBoolean") == 0) {
3324 if (cyp_ci_eq(val, "true")) {
3325 return "true";
3326 }
3327 if (cyp_ci_eq(val, "false")) {
3328 return "false";
3329 }
3330 return ""; /* not a boolean → null */
3331 }
3332 if (strcmp(func, "size") == 0 || strcmp(func, "length") == 0) {
3333 snprintf(buf, buf_sz, "%zu", strlen(val));

Callers 1

project_itemFunction · 0.85

Calls 1

cyp_ci_eqFunction · 0.85

Tested by

no test coverage detected