Skip to content

Commit 13ecb46

Browse files
larsxschneidergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8270b0 commit 13ecb46

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

strbuf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,18 @@ char *xstrdup_tolower(const char *string)
784784
return result;
785785
}
786786

787+
char *xstrdup_toupper(const char *string)
788+
{
789+
char *result;
790+
size_t len, i;
791+
792+
len = strlen(string);
793+
result = xmallocz(len);
794+
for (i = 0; i < len; i++)
795+
result[i] = toupper(string[i]);
796+
return result;
797+
}
798+
787799
char *xstrvfmt(const char *fmt, va_list ap)
788800
{
789801
struct strbuf buf = STRBUF_INIT;

strbuf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ __attribute__((format (printf,2,3)))
607607
extern int fprintf_ln(FILE *fp, const char *fmt, ...);
608608

609609
char *xstrdup_tolower(const char *);
610+
char *xstrdup_toupper(const char *);
610611

611612
/**
612613
* Create a newly allocated string using printf format. You can do this easily

0 commit comments

Comments
 (0)