strbuf: add a case insensitive starts_with()
authorLars Schneider <larsxschneider@gmail.com>
Fri, 9 Mar 2018 17:35:29 +0000 (18:35 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Mar 2018 18:17:23 +0000 (10:17 -0800)
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>
git-compat-util.h
strbuf.c
index 68b2ad531ea6f9cf1127a0e5986c523fd86b0967..95c9b34832ca0fe4a08ea73b63f89aadbb8472a0 100644 (file)
@@ -455,6 +455,7 @@ extern void (*get_warn_routine(void))(const char *warn, va_list params);
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
 extern int starts_with(const char *str, const char *prefix);
+extern int istarts_with(const char *str, const char *prefix);
 
 /*
  * If the string "str" begins with the string found in "prefix", return 1.
index a20af696bc8cf9ca0bf6730c7db1b1021d79e185..0a24c3dd76a111050ffda86a0b16d1d570ccafb9 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -11,6 +11,15 @@ int starts_with(const char *str, const char *prefix)
                        return 0;
 }
 
+int istarts_with(const char *str, const char *prefix)
+{
+       for (; ; str++, prefix++)
+               if (!*prefix)
+                       return 1;
+               else if (tolower(*str) != tolower(*prefix))
+                       return 0;
+}
+
 int skip_to_optional_arg_default(const char *str, const char *prefix,
                                 const char **arg, const char *def)
 {