From a8270b0980f88a918f9135e02e86ac6143848d95 Mon Sep 17 00:00:00 2001 From: Lars Schneider Date: Thu, 15 Feb 2018 16:27:05 +0100 Subject: strbuf: remove unnecessary NUL assignment in xstrdup_tolower() Since 3733e69464 (use xmallocz to avoid size arithmetic, 2016-02-22) we allocate the buffer for the lower case string with xmallocz(). This already ensures a NUL at the end of the allocated buffer. Remove the unnecessary assignment. Signed-off-by: Lars Schneider Signed-off-by: Junio C Hamano --- strbuf.c | 1 - 1 file changed, 1 deletion(-) (limited to 'strbuf.c') diff --git a/strbuf.c b/strbuf.c index 8007be8fba..490f7850e9 100644 --- a/strbuf.c +++ b/strbuf.c @@ -781,7 +781,6 @@ char *xstrdup_tolower(const char *string) result = xmallocz(len); for (i = 0; i < len; i++) result[i] = tolower(string[i]); - result[i] = '\0'; return result; } -- cgit v1.2.3 From 13ecb4638ed92a56e855d2e6d3a9b71c4125eb51 Mon Sep 17 00:00:00 2001 From: Lars Schneider Date: Thu, 15 Feb 2018 16:27:06 +0100 Subject: strbuf: add xstrdup_toupper() Create a copy of an existing string and make all characters upper case. Similar xstrdup_tolower(). This function is used in a subsequent commit. Signed-off-by: Lars Schneider Signed-off-by: Junio C Hamano --- strbuf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'strbuf.c') diff --git a/strbuf.c b/strbuf.c index 490f7850e9..a20af696bc 100644 --- a/strbuf.c +++ b/strbuf.c @@ -784,6 +784,18 @@ char *xstrdup_tolower(const char *string) return result; } +char *xstrdup_toupper(const char *string) +{ + char *result; + size_t len, i; + + len = strlen(string); + result = xmallocz(len); + for (i = 0; i < len; i++) + result[i] = toupper(string[i]); + return result; +} + char *xstrvfmt(const char *fmt, va_list ap) { struct strbuf buf = STRBUF_INIT; -- cgit v1.2.3 From 66b8af3e124a0c9dbad05f40c2f6d27614f34349 Mon Sep 17 00:00:00 2001 From: Lars Schneider Date: Fri, 9 Mar 2018 18:35:29 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- strbuf.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'strbuf.c') diff --git a/strbuf.c b/strbuf.c index a20af696bc..0a24c3dd76 100644 --- 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) { -- cgit v1.2.3