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

Function ha_extract_token

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

216 * the pattern has no usable token (path globs, short/regex-only patterns) —
217 * the caller then no-ops, which keeps the common cheap case cheap. */
218static bool ha_extract_token(const char *pattern, char *out, size_t out_sz) {
219 if (!pattern) {
220 return false;
221 }
222 size_t best_start = 0;
223 size_t best_len = 0;
224 size_t i = 0;
225 while (pattern[i]) {
226 if (isalpha((unsigned char)pattern[i]) || pattern[i] == '_') {
227 size_t start = i;
228 while (pattern[i] && (isalnum((unsigned char)pattern[i]) || pattern[i] == '_')) {
229 i++;
230 }
231 size_t len = i - start;
232 if (len > best_len) {
233 best_len = len;
234 best_start = start;
235 }
236 } else {
237 i++;
238 }
239 }
240 if (best_len < HA_MIN_TOKEN) {
241 return false;
242 }
243 if (best_len > HA_MAX_TOKEN) {
244 best_len = HA_MAX_TOKEN;
245 }
246 if (best_len + 1 > out_sz) {
247 best_len = out_sz - 1;
248 }
249 memcpy(out, pattern + best_start, best_len);
250 out[best_len] = '\0';
251 return true;
252}
253
254/* ── JSON helpers ─────────────────────────────────────────────────── */
255

Callers 2

ha_processFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected