From 1284c582a914c942dd2bd21b1749bf6567515d2b Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 6 Mar 2021 15:45:46 -0500 Subject: lib: add ByteToUpper --- lib/str.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/str.go') diff --git a/lib/str.go b/lib/str.go index 8211ea8..8db415f 100644 --- a/lib/str.go +++ b/lib/str.go @@ -123,15 +123,19 @@ func StrSplitAt(c byte, s string) []string { func StrToUpper(s string) string { us := "" for i := 0; i < len(s); i++ { - if 'a' <= s[i] && s[i] <= 'z' { - us += string('A' + (s[i] - 'a')) - } else { - us += string(s[i]) - } + us += string(ByteToUpper(s[i])) } return us } +func ByteToUpper(b byte) byte { + if 'a' <= b && b <= 'z' { + return 'A' + (b - 'a') + } else { + return b + } +} + // Returns true if string 's' has string 'n' in it. func StrHas(s, n string) bool { for i := 0; i < len(s); i++ { -- cgit v1.2.3