diff options
author | rsiddharth <s@ricketyspace.net> | 2021-03-06 15:45:46 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2021-03-06 15:45:46 -0500 |
commit | 1284c582a914c942dd2bd21b1749bf6567515d2b (patch) | |
tree | ed54db71b47c8e96c51beff9fd44766d7469cbd7 | |
parent | 51cce8132d7bd21f51613a1a78ea6652ffb222f4 (diff) |
lib: add ByteToUpper
-rw-r--r-- | lib/str.go | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -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++ { |