bind: correctly lowercasing all caps names
Fixes golang/go#13031 Change-Id: I6cae8e303d0d929e26c44cbdf1c243e98dabb766 Reviewed-on: https://go-review.googlesource.com/16270 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
b7734b1851
commit
8a59fd3f45
@ -212,3 +212,23 @@ func TestCustomPrefix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLowerFirst(t *testing.T) {
|
||||
testCases := []struct {
|
||||
in, want string
|
||||
}{
|
||||
{"", ""},
|
||||
{"Hello", "hello"},
|
||||
{"HelloGopher", "helloGopher"},
|
||||
{"hello", "hello"},
|
||||
{"ID", "id"},
|
||||
{"IDOrName", "idOrName"},
|
||||
{"ΓειαΣας", "γειαΣας"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
if got := lowerFirst(tc.in); got != tc.want {
|
||||
t.Errorf("lowerFirst(%q) = %q; want %q", tc.in, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1006,6 +1006,18 @@ func lowerFirst(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
r, n := utf8.DecodeRuneInString(s)
|
||||
return string(unicode.ToLower(r)) + s[n:]
|
||||
|
||||
var conv []rune
|
||||
for len(s) > 0 {
|
||||
r, n := utf8.DecodeRuneInString(s)
|
||||
if !unicode.IsUpper(r) {
|
||||
if l := len(conv); l > 1 {
|
||||
conv[l-1] = unicode.ToUpper(conv[l-1])
|
||||
}
|
||||
return string(conv) + s
|
||||
}
|
||||
conv = append(conv, unicode.ToLower(r))
|
||||
s = s[n:]
|
||||
}
|
||||
return string(conv)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user