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

Function ha_extract_token

src/cli/hook_augment.c:177–211  ·  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

175 * the pattern has no usable token (path globs, short/regex-only patterns) —
176 * the caller then no-ops, which keeps the common cheap case cheap. */
177static bool ha_extract_token(const char *pattern, char *out, size_t out_sz) {
178 if (!pattern) {
179 return false;
180 }
181 size_t best_start = 0;
182 size_t best_len = 0;
183 size_t i = 0;
184 while (pattern[i]) {
185 if (isalpha((unsigned char)pattern[i]) || pattern[i] == '_') {
186 size_t start = i;
187 while (pattern[i] && (isalnum((unsigned char)pattern[i]) || pattern[i] == '_')) {
188 i++;
189 }
190 size_t len = i - start;
191 if (len > best_len) {
192 best_len = len;
193 best_start = start;
194 }
195 } else {
196 i++;
197 }
198 }
199 if (best_len < HA_MIN_TOKEN) {
200 return false;
201 }
202 if (best_len > HA_MAX_TOKEN) {
203 best_len = HA_MAX_TOKEN;
204 }
205 if (best_len + 1 > out_sz) {
206 best_len = out_sz - 1;
207 }
208 memcpy(out, pattern + best_start, best_len);
209 out[best_len] = '\0';
210 return true;
211}
212
213/* ── JSON helpers ─────────────────────────────────────────────────── */
214

Callers 1

ha_processFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected