Created
November 9, 2014 04:53
-
-
Save tmaiaroto/5970ef8918e5074ce6d1 to your computer and use it in GitHub Desktop.
Golang: somewhat faster string uppercase / lowercase (for certain strings)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See: https://groups.google.com/forum/#!topic/golang-nuts/Il2DX4xpW3w | |
// A slightly faster lowercase function. | |
func toLower(s string) string { | |
b := make([]byte, len(s)) | |
for i := range b { | |
c := s[i] | |
if c >= 'A' && c <= 'Z' { | |
c += 'a' - 'A' | |
} | |
b[i] = c | |
} | |
return string(b) | |
} | |
// A slightly faster uppercase function. | |
func toUpper(s string) string { | |
b := make([]byte, len(s)) | |
for i := range b { | |
c := s[i] | |
if c >= 'a' && c <= 'z' { | |
c -= 'a' - 'A' | |
} | |
b[i] = c | |
} | |
return string(b) | |
} |
Depends on what ya need 🤷
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, it can be used only with latin symbols...