Skip to content

Commit 66b8af3

Browse files
larsxschneidergitster
authored andcommitted
strbuf: add a case insensitive starts_with()
Check in a case insensitive manner if one string is a prefix of another string. This function is used in a subsequent commit. Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13ecb46 commit 66b8af3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

git-compat-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ extern void (*get_warn_routine(void))(const char *warn, va_list params);
455455
extern void set_die_is_recursing_routine(int (*routine)(void));
456456

457457
extern int starts_with(const char *str, const char *prefix);
458+
extern int istarts_with(const char *str, const char *prefix);
458459

459460
/*
460461
* If the string "str" begins with the string found in "prefix", return 1.

strbuf.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ int starts_with(const char *str, const char *prefix)
1111
return 0;
1212
}
1313

14+
int istarts_with(const char *str, const char *prefix)
15+
{
16+
for (; ; str++, prefix++)
17+
if (!*prefix)
18+
return 1;
19+
else if (tolower(*str) != tolower(*prefix))
20+
return 0;
21+
}
22+
1423
int skip_to_optional_arg_default(const char *str, const char *prefix,
1524
const char **arg, const char *def)
1625
{

0 commit comments

Comments
 (0)