[PATCH v3 2/7] strbuf: add xstrdup_toupper()
- From
lars.schneider@autodesk.com <lars.schneider@autodesk.com>
- Date
- Jan 6, 2018, 00:48 UTC
- Message-ID
- <20180106004808.77513-3-lars.schneider@autodesk.com>
- In-Reply-To
- <20180106004808.77513-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> --- strbuf.c | 12 ++++++++++++ strbuf.h | 1 + 2 files changed, 13 insertions(+)
diff --git a/strbuf.c b/strbuf.c index b5d03a5029..703a1556cb 100644 --- a/strbuf.c +++ b/strbuf.c @@ -759,6 +759,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; diff --git a/strbuf.h b/strbuf.h index 0a74acb236..2bc148526f 100644 --- a/strbuf.h +++ b/strbuf.h @@ -616,6 +616,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.15.1