strbuf: add xstrdup_toupper()
authorLars Schneider <larsxschneider@gmail.com>
Thu, 15 Feb 2018 15:27:06 +0000 (16:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Feb 2018 19:36:15 +0000 (11:36 -0800)
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 <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf.c
strbuf.h
index 490f7850e963b8171032986ae18e7c3491115b40..a20af696bc8cf9ca0bf6730c7db1b1021d79e185 100644 (file)
--- 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;
index 14c8c10d66b9aaa2d8f0c109cf0dd668701cb2eb..df7ced53ed2fb895eb85e7ad1bb093024fe469bb 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -607,6 +607,7 @@ __attribute__((format (printf,2,3)))
 extern int fprintf_ln(FILE *fp, const char *fmt, ...);
 
 char *xstrdup_tolower(const char *);
+char *xstrdup_toupper(const char *);
 
 /**
  * Create a newly allocated string using printf format. You can do this easily