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>

Jeff King committed May 13, 2018 at 12:57 UTC 41a80924aec0e94309786837b6f954a3b3f19b71
1 file changed +17
git-compat-util.h
+17
@@ -956,6 +956,23 @@ static inline int sane_iscase(int x, int is_lower)
956 return (x & 0x20) == 0;
957 }
958
959 +/*
960 + * Like skip_prefix, but compare case-insensitively. Note that the comparison
961 + * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
962 + * locale-specific conversions).
963 + */
964 +static inline int skip_iprefix(const char *str, const char *prefix,
965 + const char **out)
966 +{
967 + do {
968 + if (!*prefix) {
969 + *out = str;
970 + return 1;
971 + }
972 + } while (tolower(*str++) == tolower(*prefix++));
973 + return 0;
974 +}
975 +
976 static inline int strtoul_ui(char const *s, int base, unsigned int *result)
977 {
978 unsigned long ul;