Commit 78175474 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

strings: use Go style character range comparison in ToUpper/ToLower

As noted by Brad in CL 170954 for package bytes.

Change-Id: I2772a356299e54ba5b7884d537e6649039adb9be
Reviewed-on: https://go-review.googlesource.com/c/go/+/171198
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 4166ff42
...@@ -559,7 +559,7 @@ func ToUpper(s string) string { ...@@ -559,7 +559,7 @@ func ToUpper(s string) string {
isASCII = false isASCII = false
break break
} }
hasLower = hasLower || (c >= 'a' && c <= 'z') hasLower = hasLower || ('a' <= c && c <= 'z')
} }
if isASCII { // optimize for ASCII-only strings. if isASCII { // optimize for ASCII-only strings.
...@@ -570,7 +570,7 @@ func ToUpper(s string) string { ...@@ -570,7 +570,7 @@ func ToUpper(s string) string {
b.Grow(len(s)) b.Grow(len(s))
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
c := s[i] c := s[i]
if c >= 'a' && c <= 'z' { if 'a' <= c && c <= 'z' {
c -= 'a' - 'A' c -= 'a' - 'A'
} }
b.WriteByte(c) b.WriteByte(c)
...@@ -589,7 +589,7 @@ func ToLower(s string) string { ...@@ -589,7 +589,7 @@ func ToLower(s string) string {
isASCII = false isASCII = false
break break
} }
hasUpper = hasUpper || (c >= 'A' && c <= 'Z') hasUpper = hasUpper || ('A' <= c && c <= 'Z')
} }
if isASCII { // optimize for ASCII-only strings. if isASCII { // optimize for ASCII-only strings.
...@@ -600,7 +600,7 @@ func ToLower(s string) string { ...@@ -600,7 +600,7 @@ func ToLower(s string) string {
b.Grow(len(s)) b.Grow(len(s))
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
c := s[i] c := s[i]
if c >= 'A' && c <= 'Z' { if 'A' <= c && c <= 'Z' {
c += 'a' - 'A' c += 'a' - 'A'
} }
b.WriteByte(c) b.WriteByte(c)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment