Skip to content

Commit d9eb391

Browse files
committed
refactor(util/ascii): simplify AsciiToLowerCase()
1 parent 99a3622 commit d9eb391

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/util/ascii.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
package util
22

3-
import "unicode/utf8"
4-
53
func AsciiToLowerCase(input string) string {
64
buffer := []byte(input)
7-
length := len(buffer)
85

9-
for i := 0; i < length; {
10-
r, w := utf8.DecodeRune(buffer[i:])
11-
if w == 1 && r >= 'A' && r <= 'Z' {
6+
for i := range buffer {
7+
if buffer[i] >= 'A' && buffer[i] <= 'Z' {
128
buffer[i] += 'a' - 'A'
139
}
14-
15-
i += w
1610
}
1711

1812
return string(buffer)

src/util/ascii_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ func TestAsciiToLowerCase(t *testing.T) {
1010
t.Error(lower)
1111
}
1212
}
13+
14+
func BenchmarkAsciiToLowerCase(b *testing.B) {
15+
const str = "Confucius said: \"三人行,必有我师焉\""
16+
for i := 0; i < b.N; i++ {
17+
AsciiToLowerCase(str)
18+
}
19+
}

src/util/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NormalizeFsPath(input string) (string, error) {
5151

5252
volume := filepath.VolumeName(abs)
5353
if len(volume) > 0 {
54-
// suppose on windows platform, ignore ascii case in path name
54+
// assume on windows platform, ignore ascii case in path name
5555
abs = AsciiToLowerCase(abs)
5656
}
5757

0 commit comments

Comments
 (0)