/* engram_text.c — see engram_text.h. * * Moved verbatim out of el_runtime.c (2026-08-16). Bodies are unchanged; only * `static` was dropped so they link from this translation unit, and each * function's doc comment travelled with it. */ #include "engram_text.h" #include #include /* Split q on whitespace into up to ENGRAM_MAX_QTOKENS distinct * (case-insensitive) tokens. Returns the token count. Over-long tokens are * truncated to ENGRAM_QTOK_LEN-1; over-count tokens are ignored. */ int engram_tokenize_query(const char* q, char toks[][ENGRAM_QTOK_LEN], int maxtok) { int n = 0; if (!q) return 0; const char* p = q; while (*p && n < maxtok) { while (*p && isspace((unsigned char)*p)) p++; if (!*p) break; char buf[ENGRAM_QTOK_LEN]; size_t tl = 0; while (*p && !isspace((unsigned char)*p)) { if (tl < sizeof(buf) - 1) buf[tl++] = *p; p++; } buf[tl] = '\0'; if (tl == 0) continue; int dup = 0; for (int s = 0; s < n; s++) { if (strcasecmp(toks[s], buf) == 0) { dup = 1; break; } } if (dup) continue; memcpy(toks[n], buf, tl + 1); n++; } return n; } /* Trim leading/trailing non-alphanumerics, then accept only tokens whose core * is alphanumeric plus '-' and '_' with at least 3 letters. This subsumes the * quoted-title guard (2026-07-25) and the "