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

Function py_split_pipe

internal/cbm/lsp/py_lsp.c:5584–5613  ·  view source on GitHub ↗

Split a "|"-separated list into a NULL-terminated array of arena copies. */

Source from the content-addressed store, hash-verified

5582
5583/* Split a "|"-separated list into a NULL-terminated array of arena copies. */
5584static const char **py_split_pipe(CBMArena *arena, const char *text) {
5585 if (!text || !text[0])
5586 return NULL;
5587 int count = 1;
5588 for (const char *p = text; *p; p++)
5589 if (*p == '|')
5590 count++;
5591 const char **out =
5592 (const char **)cbm_arena_alloc(arena, (size_t)(count + 1) * sizeof(const char *));
5593 if (!out)
5594 return NULL;
5595 int idx = 0;
5596 const char *start = text;
5597 for (const char *p = text;; p++) {
5598 if (*p == '|' || *p == '\0') {
5599 size_t n = (size_t)(p - start);
5600 char *s = (char *)cbm_arena_alloc(arena, n + 1);
5601 if (!s)
5602 return NULL;
5603 memcpy(s, start, n);
5604 s[n] = '\0';
5605 out[idx++] = s;
5606 if (*p == '\0')
5607 break;
5608 start = p + 1;
5609 }
5610 }
5611 out[idx] = NULL;
5612 return out;
5613}
5614
5615/* Split a class def's field_defs ("name:QN|name:QN", built by the Python
5616 * field fold in pass_lsp_cross.c) into the parallel NULL-terminated arrays a

Callers 2

py_split_field_defsFunction · 0.85
py_register_lsp_defsFunction · 0.85

Calls 1

cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected