aboutsummaryrefslogtreecommitdiff
path: root/shared.c
diff options
context:
space:
mode:
authorLukas Fleischer <cgit@cryptocrack.de>2014-01-10 12:44:37 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2014-01-10 17:04:14 +0100
commitf04b8d5c99afdc55178f1a06ff1594f5f0cc4be6 (patch)
tree7aaea2611c19c3ce30a83da982b801d3efa57536 /shared.c
parent2abce4300b90fa80845193c14d4b6849720007b1 (diff)
downloadcgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.tar.gz
cgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.tar.bz2
cgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.zip
Refactor cgit_parse_snapshots_mask()
Use Git string lists instead of str{spn,cspn,ncmp}() magic. This significantly improves readability. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/shared.c b/shared.c
index 1f6310a..01197f1 100644
--- a/shared.c
+++ b/shared.c
@@ -404,28 +404,29 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix)
int cgit_parse_snapshots_mask(const char *str)
{
+ struct string_list tokens = STRING_LIST_INIT_DUP;
+ struct string_list_item *item;
const struct cgit_snapshot_format *f;
- static const char *delim = " ";
- int tl, sl, rv = 0;
+ int rv = 0;
/* favor legacy setting */
if (atoi(str))
return 1;
- for (;;) {
- str += strspn(str, delim);
- tl = strcspn(str, delim);
- if (!tl)
- break;
+
+ string_list_split(&tokens, str, ' ', -1);
+ string_list_remove_empty_items(&tokens, 0);
+
+ for_each_string_list_item(item, &tokens) {
for (f = cgit_snapshot_formats; f->suffix; f++) {
- sl = strlen(f->suffix);
- if ((tl == sl && !strncmp(f->suffix, str, tl)) ||
- (tl == sl - 1 && !strncmp(f->suffix + 1, str, tl - 1))) {
+ if (!strcmp(item->string, f->suffix) ||
+ !strcmp(item->string, f->suffix + 1)) {
rv |= f->bit;
break;
}
}
- str += tl;
}
+
+ string_list_clear(&tokens, 0);
return rv;
}