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

Function handle_string_refs

internal/cbm/extract_unified.c:1276–1338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1274}
1275
1276static void handle_string_refs(CBMExtractCtx *ctx, TSNode node, const WalkState *state) {
1277 const char *kind = ts_node_type(node);
1278 /* JS/TS template literals: flatten ${...} substitutions to "{}" so URL-ish
1279 * template strings become string_refs with the canonical placeholder shape
1280 * shared with server route paths (issue #1006). */
1281 if (strcmp(kind, "template_string") == 0) {
1282 const char *flat = cbm_template_string_text(ctx->arena, node, ctx->source);
1283 if (!flat) {
1284 return;
1285 }
1286 int kind_val = cbm_classify_string(flat, (int)strlen(flat));
1287 if (kind_val < 0) {
1288 return;
1289 }
1290 CBMStringRef ref = {
1291 .value = flat,
1292 .enclosing_func_qn =
1293 state->enclosing_func_qn ? state->enclosing_func_qn : ctx->module_qn,
1294 .kind = (CBMStringRefKind)kind_val,
1295 };
1296 cbm_stringref_push(&ctx->result->string_refs, ctx->arena, ref);
1297 return;
1298 }
1299 if (!is_string_node(kind)) {
1300 return;
1301 }
1302
1303 /* Extract string content */
1304 char *text = cbm_node_text(ctx->arena, node, ctx->source);
1305 if (!text || !text[0]) {
1306 return;
1307 }
1308
1309 /* Strip quotes if present */
1310 int len = (int)strlen(text);
1311 const char *content = text;
1312 if (len >= CBM_QUOTE_PAIR && (text[0] == '"' || text[0] == '\'')) {
1313 content = text + SKIP_ONE;
1314 len -= PAIR_LEN;
1315 if (len <= 0) {
1316 return;
1317 }
1318 }
1319
1320 /* Classify */
1321 int kind_val = cbm_classify_string(content, len);
1322 if (kind_val < 0) {
1323 return;
1324 }
1325
1326 /* Build null-terminated content string in arena */
1327 char *val = cbm_arena_strndup(ctx->arena, content, (size_t)len);
1328 if (!val) {
1329 return;
1330 }
1331
1332 CBMStringRef ref = {
1333 .value = val,

Callers 1

cbm_extract_unifiedFunction · 0.85

Calls 6

cbm_template_string_textFunction · 0.85
cbm_classify_stringFunction · 0.85
cbm_stringref_pushFunction · 0.85
is_string_nodeFunction · 0.85
cbm_node_textFunction · 0.85
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected