Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-05-13 19:57:14 +0300
committerJeff King <peff@peff.net>2018-05-22 06:50:11 +0300
commit41a80924aec0e94309786837b6f954a3b3f19b71 (patch)
tree80644e83e5d43d739852bf86afdf57e7ea381284 /git-compat-util.h
parentdc2d9ba3187fcd0ca8eeab9aa9ddef70cf8627a6 (diff)
skip_prefix: add case-insensitive variant
We have the convenient skip_prefix() helper, but if you want to do case-insensitive matching, you're stuck doing it by hand. We could add an extra parameter to the function to let callers ask for this, but the function is small and somewhat performance-critical. Let's just re-implement it for the case-insensitive version. Signed-off-by: Jeff King <peff@peff.net>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 59866d72fa..4be15e5eb2 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -956,6 +956,23 @@ static inline int sane_iscase(int x, int is_lower)
return (x & 0x20) == 0;
}
+/*
+ * Like skip_prefix, but compare case-insensitively. Note that the comparison
+ * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
+ * locale-specific conversions).
+ */
+static inline int skip_iprefix(const char *str, const char *prefix,
+ const char **out)
+{
+ do {
+ if (!*prefix) {
+ *out = str;
+ return 1;
+ }
+ } while (tolower(*str++) == tolower(*prefix++));
+ return 0;
+}
+
static inline int strtoul_ui(char const *s, int base, unsigned int *result)
{
unsigned long ul;