* append a substring [p..end] to list; return number of things it * appended to the list. */
| 295 | * appended to the list. |
| 296 | */ |
| 297 | static int append_one(struct string_list *list, |
| 298 | const char *p, const char *end, |
| 299 | int in_place, unsigned flags) |
| 300 | { |
| 301 | if (!end) |
| 302 | end = p + strlen(p); |
| 303 | |
| 304 | if ((flags & STRING_LIST_SPLIT_TRIM)) { |
| 305 | /* rtrim */ |
| 306 | for (; p < end; end--) |
| 307 | if (!isspace(end[-1])) |
| 308 | break; |
| 309 | } |
| 310 | |
| 311 | if ((flags & STRING_LIST_SPLIT_NONEMPTY) && (end <= p)) |
| 312 | return 0; |
| 313 | |
| 314 | if (in_place) { |
| 315 | *((char *)end) = '\0'; |
| 316 | string_list_append(list, p); |
| 317 | } else { |
| 318 | string_list_append_nodup(list, xmemdupz(p, end - p)); |
| 319 | } |
| 320 | return 1; |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * Unfortunately this cannot become a public interface, as _in_place() |
no test coverage detected