mojang cant get their cases straight

i had to implement like 4 cases just  to parse that file
This commit is contained in:
adman
2026-04-21 09:38:14 +02:00
parent d87c362270
commit f6001c8b22
7 changed files with 265 additions and 33 deletions
+43
View File
@@ -0,0 +1,43 @@
package util
import (
"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 SnakeCase(s string) string {
ret := ""
for i, c := range s {
if unicode.IsUpper(c) {
if i > 0 {
ret += "_"
}
c = unicode.ToLower(c)
}
ret += string(c)
}
return ret
}
func FirstLetterLower(s string) string {
return string(unicode.ToLower(rune(s[0]))) + s[1:]
}
+29
View File
@@ -0,0 +1,29 @@
package util_test
import (
"testing"
"github.com/admin-else/strom/util"
)
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 := util.CamelCase(test.input)
if result != test.expected {
t.Errorf("CamelCase(%q) = %q; expected %q", test.input, result, test.expected)
}
}
}