The first element of a collection written at `p` ([..], (..), {..}, * listOf(..), &.{..}), copied into `out`. False when `p` is no collection. */
| 591 | /* The first element of a collection written at `p` ([..], (..), {..}, |
| 592 | * listOf(..), &.{..}), copied into `out`. False when `p` is no collection. */ |
| 593 | static bool spawn_first_element(const char *p, char *out, size_t n) { |
| 594 | const char *open = p; |
| 595 | while (*open && (spawn_word_char(*open) || strchr("!.&:<> ", *open) || |
| 596 | (open[0] == '[' && open[1] == ']'))) { |
| 597 | open += (open[0] == '[') ? 2 : 1; |
| 598 | } |
| 599 | if ((*open != '[' && *open != '(' && *open != '{') || |
| 600 | !spawn_collection_prefix(p, (size_t)(open - p))) { |
| 601 | return false; |
| 602 | } |
| 603 | p = open; |
| 604 | const char *start = spawn_skip_space(p + 1); |
| 605 | int depth = 0; |
| 606 | const char *end = start; |
| 607 | for (; *end; end++) { |
| 608 | if (*end == '"' || *end == '\'' || *end == '`') { |
| 609 | const char *close = strchr(end + 1, *end); |
| 610 | if (!close) { |
| 611 | break; |
| 612 | } |
| 613 | end = close; |
| 614 | } else if (strchr("[({", *end)) { |
| 615 | depth++; |
| 616 | } else if (strchr("])}", *end)) { |
| 617 | if (depth-- == 0) { |
| 618 | break; |
| 619 | } |
| 620 | } else if (*end == ',' && depth == 0) { |
| 621 | break; |
| 622 | } |
| 623 | } |
| 624 | size_t len = (size_t)(end - start); |
| 625 | if (len == 0 || len >= n) { |
| 626 | return false; |
| 627 | } |
| 628 | memcpy(out, start, len); |
| 629 | out[len] = '\0'; |
| 630 | return true; |
| 631 | } |
| 632 | |
| 633 | /* The program literal an argument spells: a leading literal, or the first |
| 634 | * element of a collection when that element is one. A program held in a |
no test coverage detected