Skip to content

Commit 41a8092

Browse files
committed
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 <[email protected]>
1 parent dc2d9ba commit 41a8092

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

git-compat-util.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,23 @@ static inline int sane_iscase(int x, int is_lower)
956956
return (x & 0x20) == 0;
957957
}
958958

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+
959976
static inline int strtoul_ui(char const *s, int base, unsigned int *result)
960977
{
961978
unsigned long ul;

0 commit comments

Comments
 (0)