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

Function py_split_subscript_args

internal/cbm/lsp/py_lsp.c:3840–3885  ·  view source on GitHub ↗

Split a comma-separated argument string at depth 0 (ignoring commas * inside [], (), {}). Returns NULL-terminated arena array of trimmed * substring copies. Caller passes the inside of `[...]`. */

Source from the content-addressed store, hash-verified

3838 * inside [], (), {}). Returns NULL-terminated arena array of trimmed
3839 * substring copies. Caller passes the inside of `[...]`. */
3840static const char **py_split_subscript_args(CBMArena *arena, const char *s, int *out_n) {
3841 if (!s) {
3842 *out_n = 0;
3843 return NULL;
3844 }
3845 int cap = 8;
3846 const char **out =
3847 (const char **)cbm_arena_alloc(arena, (size_t)(cap + 1) * sizeof(const char *));
3848 if (!out) {
3849 *out_n = 0;
3850 return NULL;
3851 }
3852 int n = 0;
3853 int depth = 0;
3854 size_t len = strlen(s);
3855 size_t start = 0;
3856 for (size_t i = 0; i <= len; i++) {
3857 char c = (i < len) ? s[i] : ',';
3858 if (c == '[' || c == '(' || c == '{')
3859 depth++;
3860 else if (c == ']' || c == ')' || c == '}')
3861 depth--;
3862 else if (c == ',' && depth == 0) {
3863 char *part = py_trim_ws(arena, s + start, i - start);
3864 if (part && part[0]) {
3865 if (n >= cap) {
3866 int new_cap = cap * 2;
3867 const char **grown = (const char **)cbm_arena_alloc(
3868 arena, (size_t)(new_cap + 1) * sizeof(const char *));
3869 if (grown) {
3870 for (int q = 0; q < n; q++)
3871 grown[q] = out[q];
3872 out = grown;
3873 cap = new_cap;
3874 }
3875 }
3876 if (n < cap)
3877 out[n++] = part;
3878 }
3879 start = i + 1;
3880 }
3881 }
3882 out[n] = NULL;
3883 *out_n = n;
3884 return out;
3885}
3886
3887static const CBMType *py_parse_type_text_qn(CBMArena *arena, const char *ann,
3888 const char *module_qn) {

Callers 2

py_parse_type_text_qnFunction · 0.85
py_resolve_annotationFunction · 0.85

Calls 2

py_trim_wsFunction · 0.85
cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected