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

Function ha_extract_token

src/cli/hook_augment.c:93–127  ·  view source on GitHub ↗

── pattern → token ────────────────────────────────────────────── * Extract the longest identifier-like run ([A-Za-z_][A-Za-z0-9_]*) of at * least HA_MIN_TOKEN chars. Pure-identifier output means it is always safe * to embed in a regex (name_pattern) with no escaping. Returns false when * the pattern has no usable token (path globs, short/regex-only patterns) — * the caller then no-ops, which

Source from the content-addressed store, hash-verified

91 * the pattern has no usable token (path globs, short/regex-only patterns) —
92 * the caller then no-ops, which keeps the common cheap case cheap. */
93static bool ha_extract_token(const char *pattern, char *out, size_t out_sz) {
94 if (!pattern) {
95 return false;
96 }
97 size_t best_start = 0;
98 size_t best_len = 0;
99 size_t i = 0;
100 while (pattern[i]) {
101 if (isalpha((unsigned char)pattern[i]) || pattern[i] == '_') {
102 size_t start = i;
103 while (pattern[i] && (isalnum((unsigned char)pattern[i]) || pattern[i] == '_')) {
104 i++;
105 }
106 size_t len = i - start;
107 if (len > best_len) {
108 best_len = len;
109 best_start = start;
110 }
111 } else {
112 i++;
113 }
114 }
115 if (best_len < HA_MIN_TOKEN) {
116 return false;
117 }
118 if (best_len > HA_MAX_TOKEN) {
119 best_len = HA_MAX_TOKEN;
120 }
121 if (best_len + 1 > out_sz) {
122 best_len = out_sz - 1;
123 }
124 memcpy(out, pattern + best_start, best_len);
125 out[best_len] = '\0';
126 return true;
127}
128
129/* ── JSON helpers ─────────────────────────────────────────────────── */
130

Callers 1

cbm_cmd_hook_augmentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected