Split a "|"-separated list into a NULL-terminated array of arena copies. */
| 4420 | |
| 4421 | /* Split a "|"-separated list into a NULL-terminated array of arena copies. */ |
| 4422 | static const char **php_split_pipe(CBMArena *arena, const char *text) { |
| 4423 | if (!text || !text[0]) |
| 4424 | return NULL; |
| 4425 | int count = 1; |
| 4426 | for (const char *p = text; *p; p++) |
| 4427 | if (*p == '|') |
| 4428 | count++; |
| 4429 | const char **out = |
| 4430 | (const char **)cbm_arena_alloc(arena, (size_t)(count + 1) * sizeof(const char *)); |
| 4431 | if (!out) |
| 4432 | return NULL; |
| 4433 | int idx = 0; |
| 4434 | const char *start = text; |
| 4435 | for (const char *p = text;; p++) { |
| 4436 | if (*p == '|' || *p == '\0') { |
| 4437 | size_t n = (size_t)(p - start); |
| 4438 | char *s = (char *)cbm_arena_alloc(arena, n + 1); |
| 4439 | if (!s) |
| 4440 | return NULL; |
| 4441 | memcpy(s, start, n); |
| 4442 | s[n] = '\0'; |
| 4443 | out[idx++] = s; |
| 4444 | if (*p == '\0') |
| 4445 | break; |
| 4446 | start = p + 1; |
| 4447 | } |
| 4448 | } |
| 4449 | out[idx] = NULL; |
| 4450 | return out; |
| 4451 | } |
| 4452 | |
| 4453 | /* Build a registry from caller-supplied CBMLSPDef[] — covers both the source |
| 4454 | * file's own defs and cross-file referenced defs. PHP labels recognised: |
no test coverage detected