test-string-list.con commit string_list: add two new functions for splitting strings (ff919f9)
   1#include "cache.h"
   2#include "string-list.h"
   3
   4void write_list(const struct string_list *list)
   5{
   6        int i;
   7        for (i = 0; i < list->nr; i++)
   8                printf("[%d]: \"%s\"\n", i, list->items[i].string);
   9}
  10
  11int main(int argc, char **argv)
  12{
  13        if (argc == 5 && !strcmp(argv[1], "split")) {
  14                struct string_list list = STRING_LIST_INIT_DUP;
  15                int i;
  16                const char *s = argv[2];
  17                int delim = *argv[3];
  18                int maxsplit = atoi(argv[4]);
  19
  20                i = string_list_split(&list, s, delim, maxsplit);
  21                printf("%d\n", i);
  22                write_list(&list);
  23                string_list_clear(&list, 0);
  24                return 0;
  25        }
  26
  27        if (argc == 5 && !strcmp(argv[1], "split_in_place")) {
  28                struct string_list list = STRING_LIST_INIT_NODUP;
  29                int i;
  30                char *s = xstrdup(argv[2]);
  31                int delim = *argv[3];
  32                int maxsplit = atoi(argv[4]);
  33
  34                i = string_list_split_in_place(&list, s, delim, maxsplit);
  35                printf("%d\n", i);
  36                write_list(&list);
  37                string_list_clear(&list, 0);
  38                free(s);
  39                return 0;
  40        }
  41
  42        fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
  43                argv[1] ? argv[1] : "(there was none)");
  44        return 1;
  45}