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

Function cbm_template_string_text

internal/cbm/helpers.c:2331–2362  ·  view source on GitHub ↗

Flatten a JS/TS `template_string` node into plain text (issue #1006). * String fragments are kept verbatim; each ${...} substitution becomes the * "{}" placeholder so client URLs built from template literals share the * canonical parameter shape of server-side route paths * (`/things/${id}/x` -> "/things/{}/x"). Returns NULL when the node yields * no text or exceeds the route-sized buffer. */

Source from the content-addressed store, hash-verified

2329 * (`/things/${id}/x` -> "/things/{}/x"). Returns NULL when the node yields
2330 * no text or exceeds the route-sized buffer. */
2331const char *cbm_template_string_text(CBMArena *a, TSNode node, const char *source) {
2332 enum { TPL_BUF = 512 };
2333 char buf[TPL_BUF];
2334 size_t pos = 0;
2335 uint32_t nc = ts_node_named_child_count(node);
2336 for (uint32_t i = 0; i < nc; i++) {
2337 TSNode c = ts_node_named_child(node, i);
2338 const char *k = ts_node_type(c);
2339 if (strcmp(k, "string_fragment") == 0) {
2340 char *frag = cbm_node_text(a, c, source);
2341 if (!frag) {
2342 continue;
2343 }
2344 size_t fl = strlen(frag);
2345 if (pos + fl >= TPL_BUF) {
2346 return NULL;
2347 }
2348 memcpy(buf + pos, frag, fl);
2349 pos += fl;
2350 } else if (strcmp(k, "template_substitution") == 0) {
2351 if (pos + PAIR_LEN >= TPL_BUF) {
2352 return NULL;
2353 }
2354 buf[pos++] = '{';
2355 buf[pos++] = '}';
2356 }
2357 }
2358 if (pos == 0) {
2359 return NULL;
2360 }
2361 return cbm_arena_strndup(a, buf, pos);
2362}

Callers 5

extract_call_argsFunction · 0.85
extract_string_valueFunction · 0.85
extract_positional_urlFunction · 0.85
handle_string_constantsFunction · 0.85
handle_string_refsFunction · 0.85

Calls 2

cbm_node_textFunction · 0.85
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected