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

Function cbm_str_split

src/foundation/str_util.c:210–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210char **cbm_str_split(CBMArena *a, const char *s, char delim, int *out_count) {
211 if (!s || !out_count) {
212 return NULL;
213 }
214
215 /* Count parts */
216 int count = SKIP_ONE;
217 for (const char *p = s; *p; p++) {
218 if (*p == delim) {
219 count++;
220 }
221 }
222
223 char **result = (char **)cbm_arena_alloc(a, (size_t)(count + SKIP_ONE) * sizeof(char *));
224 if (!result) {
225 return NULL;
226 }
227
228 int idx = 0;
229 const char *start = s;
230 for (const char *p = s;; p++) {
231 if (*p == delim || *p == '\0') {
232 size_t part_len = (size_t)(p - start);
233 result[idx++] = cbm_arena_strndup(a, start, part_len);
234 if (*p == '\0') {
235 break;
236 }
237 start = p + SKIP_ONE;
238 }
239 }
240
241 result[idx] = NULL;
242 *out_count = count;
243 return result;
244}
245
246bool cbm_validate_shell_arg(const char *s) {
247 if (!s) {

Callers 1

test_str_util.cFile · 0.85

Calls 2

cbm_arena_allocFunction · 0.70
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected