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

Function search_scan_patterns_parse

src/mcp/mcp.c:16068–16111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16066}
16067
16068static bool search_scan_patterns_parse(search_scan_patterns_t *patterns, const char *pattern,
16069 bool use_regex) {
16070 memset(patterns, 0, sizeof(*patterns));
16071 int count = 1;
16072 for (const char *p = pattern; *p; p++) {
16073 count += *p == '\n' ? SKIP_ONE : 0;
16074 }
16075 patterns->items = cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)count * sizeof(char *));
16076 patterns->lengths = cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)count * sizeof(size_t));
16077 patterns->regexes =
16078 use_regex ? cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)count * sizeof(cbm_regex_t)) : NULL;
16079 if (!patterns->items || !patterns->lengths || (use_regex && !patterns->regexes)) {
16080 search_scan_patterns_free(patterns);
16081 return false;
16082 }
16083 const char *start = pattern;
16084 for (int i = 0; i < count; i++) {
16085 const char *end = strchr(start, '\n');
16086 size_t length = end ? (size_t)(end - start) : strlen(start);
16087 patterns->items[i] = cbm_alloc(CBM_MEM_CLASS_OTHER, length + SKIP_ONE);
16088 if (!patterns->items[i]) {
16089 patterns->count = i;
16090 search_scan_patterns_free(patterns);
16091 return false;
16092 }
16093 memcpy(patterns->items[i], start, length);
16094 patterns->items[i][length] = '\0';
16095 patterns->lengths[i] = length;
16096 patterns->any_empty = patterns->any_empty || length == 0;
16097 start = end ? end + SKIP_ONE : start + length;
16098 }
16099 patterns->count = count;
16100 for (int i = 0; use_regex && i < count; i++) {
16101 if (patterns->lengths[i] > 0 &&
16102 cbm_regcomp(&patterns->regexes[i], patterns->items[i],
16103 CBM_REG_EXTENDED | CBM_REG_NOSUB) != CBM_REG_OK) {
16104 patterns->compiled = i;
16105 search_scan_patterns_free(patterns);
16106 return false;
16107 }
16108 patterns->compiled = i + SKIP_ONE;
16109 }
16110 return true;
16111}
16112
16113/* First occurrence of needle in hay; memmem where the C library has it. */
16114static const char *search_scan_find(const char *hay, size_t hay_length, const char *needle,

Callers 1

search_scan_in_processFunction · 0.85

Calls 4

cbm_callocFunction · 0.85
cbm_allocFunction · 0.85
cbm_regcompFunction · 0.85

Tested by

no test coverage detected