[PATCH 2/5] strbuf: add xstrdup_toupper()
- From
tboegi@web.de <tboegi@web.de>
- Date
- Dec 31, 2017, 08:05 UTC
- Message-ID
- <20171231080554.22301-1-tboegi@web.de>
- In-Reply-To
- <20171229152222.39680-1-lars.schneider@autodesk.com>
From: Lars Schneider <larsxschneider@gmail.com>
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: Torsten Bögershausen <tboegi@web.de> --- strbuf.c | 13 +++++++++++++ strbuf.h | 1 + 2 files changed, 14 insertions(+)
diff --git a/strbuf.c b/strbuf.c index 8007be8fba..ee05626dc1 100644 --- a/strbuf.c +++ b/strbuf.c @@ -785,6 +785,19 @@ 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]); + result[i] = '\0'; + return result; +} + char *xstrvfmt(const char *fmt, va_list ap) { struct strbuf buf = STRBUF_INIT; diff --git a/strbuf.h b/strbuf.h index 14c8c10d66..df7ced53ed 100644 --- 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
-- 2.16.0.rc0.4.ga4e00d4fa4