mojang cant get their cases straight
i had to implement like 4 cases just to parse that file
This commit is contained in:
@@ -4,28 +4,8 @@ import (
|
||||
"cmp"
|
||||
"maps"
|
||||
"slices"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var boundaries = []rune{' ', '_', '-', '.', ',', ';', ':', '(', ')', '[', ']', '{', '}'}
|
||||
|
||||
func CamelCase(s string) string {
|
||||
ret := ""
|
||||
atWordBoundary := true
|
||||
for _, c := range s {
|
||||
if slices.Contains(boundaries, c) {
|
||||
atWordBoundary = true
|
||||
continue
|
||||
}
|
||||
if atWordBoundary && unicode.IsLower(c) {
|
||||
c = unicode.ToUpper(c)
|
||||
}
|
||||
atWordBoundary = false
|
||||
ret += string(c)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func OrderedKeys[Map map[K]V, K cmp.Ordered, V any](m Map) []K {
|
||||
keysIter := maps.Keys(m)
|
||||
keys := slices.Collect(keysIter)
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCamelCase(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"hello world", "HelloWorld"},
|
||||
{"test_case", "TestCase"},
|
||||
{"simple-test", "SimpleTest"},
|
||||
{"already.Camel", "AlreadyCamel"},
|
||||
{"UPPER_CASE", "UPPERCASE"},
|
||||
{"mixed_Case_string", "MixedCaseString"},
|
||||
{"", ""},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := CamelCase(test.input)
|
||||
if result != test.expected {
|
||||
t.Errorf("CamelCase(%q) = %q; expected %q", test.input, result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user