From: cgit at cryptocrack.de (Lukas Fleischer)
Subject: [PATCH 3/4] Refactor cgit_parse_snapshots_mask()
Date: Fri, 10 Jan 2014 12:44:37 +0100 [thread overview]
Message-ID: <1389354278-9561-3-git-send-email-cgit@cryptocrack.de> (raw)
In-Reply-To: <1389354278-9561-1-git-send-email-cgit@cryptocrack.de>
Use Git string lists instead of str{spn,cspn,ncmp}() magic. This
significantly improves readability.
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
shared.c | 23 ++++++++++++-----------
1 file 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;
}
--
1.8.5.2
next prev parent reply other threads:[~2014-01-10 11:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-10 11:44 [PATCH 1/4] Replace most uses of strncmp() with prefixcmp() cgit
2014-01-10 11:44 ` [PATCH 2/4] Disallow use of undocumented snapshot delimiters cgit
2014-01-10 16:04 ` Jason
2014-01-10 11:44 ` cgit [this message]
2014-01-10 16:04 ` [PATCH 3/4] Refactor cgit_parse_snapshots_mask() Jason
2014-01-10 11:44 ` [PATCH 4/4] ui-snapshot.c: Do not reinvent suffixcmp() cgit
2014-01-10 16:05 ` Jason
2014-01-10 16:02 ` [PATCH 1/4] Replace most uses of strncmp() with prefixcmp() Jason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1389354278-9561-3-git-send-email-cgit@cryptocrack.de \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).