| 103 | */ |
| 104 | |
| 105 | static const char ** |
| 106 | arrayize(const char *str, const char *chars, int *size) |
| 107 | { |
| 108 | int i; |
| 109 | char *ptr; |
| 110 | const char *cptr; |
| 111 | const char **res = NULL; |
| 112 | |
| 113 | /* count the sub-strings */ |
| 114 | for (i = 0, cptr = str; *cptr; i++) { |
| 115 | int count = strcspn(cptr, chars); |
| 116 | cptr += count; |
| 117 | if (*cptr) |
| 118 | ++cptr; |
| 119 | } |
| 120 | |
| 121 | /* alloc the array */ |
| 122 | if ((ptr = allocstr(str)) != NULL) { |
| 123 | if ((res = allocarray(++i)) == NULL) |
| 124 | free((void *)(uintptr_t)(const void *)str); |
| 125 | else { |
| 126 | /* now split the string */ |
| 127 | i = 0; |
| 128 | while (*ptr) { |
| 129 | int count = strcspn(ptr, chars); |
| 130 | res[i++] = ptr; |
| 131 | ptr += count; |
| 132 | if (*ptr) |
| 133 | *ptr++ = '\0'; |
| 134 | } |
| 135 | res[i] = NULL; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (size) |
| 140 | *size = i; |
| 141 | |
| 142 | return res; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | /* |
no test coverage detected