123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package kata
- import (
- "fmt"
- "strings"
- "unicode"
- )
- func ToCamelCase(s string) string {
- // Only handle the underscore case.
- u := strings.ReplaceAll(s, `-`, `_`)
- fmt.Println("Checking", u)
- res := make([]rune, 0, len(u))
- atFirst := true
- atInitial := true
- for _, r := range u {
- fmt.Printf("%c: ", r)
- if r == '_' {
- fmt.Println("Skipping _, setting Initial")
- atInitial = true
- continue
- }
- if atFirst {
- fmt.Println("First")
- res = append(res, r)
- atFirst = false
- atInitial = false
- continue
- } else if atInitial {
- fmt.Println("atInitial")
- res = append(res, unicode.ToUpper(r))
- } else {
- fmt.Println("not")
- res = append(res, r)
- }
- atInitial = false
- }
- return string(res)
- }
|