diff --git a/pkg/strcase/strcase.go b/pkg/strcase/strcase.go index b1b1b327a..45726cfd3 100644 --- a/pkg/strcase/strcase.go +++ b/pkg/strcase/strcase.go @@ -8,7 +8,6 @@ package strcase import ( "strings" "unicode" - "unicode/utf8" ) // Delimited converts a string to delimited.lower.case, here using `.` as delimiter. @@ -41,23 +40,10 @@ func convert(s string, _case int, d rune) string { n := strings.Builder{} n.Grow(len(s) + 2) // Allow adding at least 2 delimiters without another allocation. - var pos int - var prevRune int32 + var prevRune rune - for _, r := range s[pos:] { - n.WriteRune(unicode.To(_case, r)) - - pos += utf8.RuneLen(r) - prevRune = r - - // This loop just extracts the first rune of the string, - // without needing to allocate a new slice of runes as - // range iterates over the runes of the string. - break - } - - for _, r := range s[pos:] { - if unicode.IsUpper(r) && (unicode.IsNumber(prevRune) || unicode.IsLower(prevRune)) { + for i, r := range s { + if i > 0 && unicode.IsUpper(r) && (unicode.IsNumber(prevRune) || unicode.IsLower(prevRune)) { n.WriteRune(d) } diff --git a/pkg/strcase/strcase_test.go b/pkg/strcase/strcase_test.go index 3ab4d056c..e689f0ae6 100644 --- a/pkg/strcase/strcase_test.go +++ b/pkg/strcase/strcase_test.go @@ -33,7 +33,7 @@ var tests = [][]string{ {"icinga💯points", "icinga💯points"}, {"😃🙃😀", "😃🙃😀"}, {"こんにちは", "こんにちは"}, - {"\xff\xfe\xfd", "�"}, + {"\xff\xfe\xfd", "���"}, } func TestSnake(t *testing.T) {