MCPcopy Index your code
hub / github.com/git/git / split_string

Function split_string

string-list.c:333–364  ·  view source on GitHub ↗

* Unfortunately this cannot become a public interface, as _in_place() * wants to have "const char *string" while the other variant wants to * have "char *string" for type safety. * * This accepts "const char *string" to allow both wrappers to use it; * it internally casts away the constness when in_place is true by * taking advantage of strpbrk() that takes a "const char *" arg and * return

Source from the content-addressed store, hash-verified

331 * returns "char *" pointer into that const string. Yucky but works ;-).
332 */
333static int split_string(struct string_list *list, const char *string, const char *delim,
334 int maxsplit, int in_place, unsigned flags)
335{
336 int count = 0;
337 const char *p = string;
338
339 if (in_place && list->strdup_strings)
340 BUG("string_list_split_in_place() called with strdup_strings");
341 else if (!in_place && !list->strdup_strings)
342 BUG("string_list_split() called without strdup_strings");
343
344 for (;;) {
345 const char *end;
346
347 if (flags & STRING_LIST_SPLIT_TRIM) {
348 /* ltrim */
349 while (*p && isspace(*p))
350 p++;
351 }
352
353 if (0 <= maxsplit && maxsplit <= count)
354 end = NULL;
355 else
356 end = strpbrk(p, delim);
357
358 count += append_one(list, p, end, in_place, flags);
359
360 if (!end)
361 return count;
362 p = end + 1;
363 }
364}
365
366int string_list_split(struct string_list *list, const char *string,
367 const char *delim, int maxsplit)

Callers 4

string_list_splitFunction · 0.85
string_list_split_fFunction · 0.85

Calls 1

append_oneFunction · 0.85

Tested by

no test coverage detected