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

Function qn_safe_segment

internal/cbm/extract_defs.c:3785–3818  ·  view source on GitHub ↗

Push a simple class definition (used by config language extractors). Replace each run of whitespace in `name` with a single '-' so the value is a well-formed QN segment. Markdown headings (e.g. "Codebase Memory") legitimately contain spaces; embedding them verbatim in a QN makes it malformed. Returns the original pointer when there is no whitespace to collapse. The human-readable def.name is kept

Source from the content-addressed store, hash-verified

3783// original pointer when there is no whitespace to collapse. The human-readable
3784// def.name is kept intact; only the QN segment is slugified.
3785static const char *qn_safe_segment(CBMArena *a, const char *name) {
3786 if (!name) {
3787 return name;
3788 }
3789 bool has_ws = false;
3790 for (const char *p = name; *p; p++) {
3791 if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') {
3792 has_ws = true;
3793 break;
3794 }
3795 }
3796 if (!has_ws) {
3797 return name;
3798 }
3799 char *out = cbm_arena_strdup(a, name);
3800 if (!out) {
3801 return name;
3802 }
3803 char *w = out;
3804 bool in_ws = false;
3805 for (char *r = out; *r; r++) {
3806 if (*r == ' ' || *r == '\t' || *r == '\n' || *r == '\r') {
3807 if (!in_ws && w != out) {
3808 *w++ = '-';
3809 }
3810 in_ws = true;
3811 } else {
3812 *w++ = *r;
3813 in_ws = false;
3814 }
3815 }
3816 *w = '\0';
3817 return out;
3818}
3819
3820static void push_simple_class_def(CBMExtractCtx *ctx, TSNode node, char *name, const char *label) {
3821 CBMArena *a = ctx->arena;

Callers 1

push_simple_class_defFunction · 0.85

Calls 1

cbm_arena_strdupFunction · 0.70

Tested by

no test coverage detected