The top-level comma-separated parts of the list opened at `open` ('('). * Returns their count (at most `max`); *end: the closing ')'. */
| 1099 | /* The top-level comma-separated parts of the list opened at `open` ('('). |
| 1100 | * Returns their count (at most `max`); *end: the closing ')'. */ |
| 1101 | static int gc_args(const char *open, const char *starts[], size_t lens[], int max, |
| 1102 | const char **end) { |
| 1103 | int n = 0; |
| 1104 | int depth = 0; |
| 1105 | const char *start = open + SKIP_ONE; |
| 1106 | for (const char *p = open; *p;) { |
| 1107 | const char *q = gc_skip(p); |
| 1108 | if (q != p) { |
| 1109 | p = q; |
| 1110 | continue; |
| 1111 | } |
| 1112 | if (strchr("([{", *p)) { |
| 1113 | depth++; |
| 1114 | } else if (strchr(")]}", *p)) { |
| 1115 | depth--; |
| 1116 | if (depth == 0) { |
| 1117 | if (n < max && p > start) { |
| 1118 | starts[n] = start; |
| 1119 | lens[n++] = (size_t)(p - start); |
| 1120 | } |
| 1121 | *end = p; |
| 1122 | return n; |
| 1123 | } |
| 1124 | } else if (*p == ',' && depth == SKIP_ONE && n < max) { |
| 1125 | starts[n] = start; |
| 1126 | lens[n++] = (size_t)(p - start); |
| 1127 | start = p + SKIP_ONE; |
| 1128 | } |
| 1129 | p++; |
| 1130 | } |
| 1131 | *end = open + strlen(open); |
| 1132 | return n; |
| 1133 | } |
| 1134 | |
| 1135 | static void gc_trim(const char **s, size_t *n) { |
| 1136 | while (*n && strchr(" \t\r\n", **s)) { |
no test coverage detected