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 <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Mar 9, 2018 at 18:35 UTC
66b8af3e124a0c9dbad05f40c2f6d27614f34349
2 files changed
+10
git-compat-util.h
+1
@@ -455,6 +455,7 @@ extern void (*get_warn_routine(void))(const char *warn, va_list params);
455
extern void set_die_is_recursing_routine(int (*routine)(void));
456
457
extern int starts_with(const char *str, const char *prefix);
458
+extern int istarts_with(const char *str, const char *prefix);
459
460
/*
461
* If the string "str" begins with the string found in "prefix", return 1.
strbuf.c
+9
@@ -11,6 +11,15 @@ int starts_with(const char *str, const char *prefix)
11
return 0;
12
}
13
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
+
23
int skip_to_optional_arg_default(const char *str, const char *prefix,
24
const char **arg, const char *def)
25
{