Skip to content

Commit

Permalink
cmd/fitgen/internal/profile: don't use deprecated strings.Title
Browse files Browse the repository at this point in the history
  • Loading branch information
tormoder committed Jun 23, 2022
1 parent 2ecbe1d commit fd00e0d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/fitgen/internal/profile/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,38 @@ package profile
import (
"fmt"
"log"
"regexp"
"strconv"
"strings"
"unicode"
"unicode/utf8"

"github.com/tormoder/fit/internal/types"
)

var camelRegex = regexp.MustCompile("[0-9A-Za-z]+")

func toCamelCase(s string) string {
chunks := camelRegex.FindAllString(s, -1)
if s == "" {
return s
}
chunks := strings.Split(s, "_")
for i, val := range chunks {
chunks[i] = strings.Title(val)
chunks[i] = toUpper(val)
}
return strings.Join(chunks, "")
}

func toUpper(s string) string {
if len(s) > 0 {
r, size := utf8.DecodeRuneInString(s)
if r != utf8.RuneError || size > 1 {
up := unicode.ToUpper(r)
if up != r {
s = string(up) + s[size:]
}
}
}
return s
}

var typeQuirks = map[string]string{
"activity": "activity_mode",
"file": "file_type",
Expand Down

0 comments on commit fd00e0d

Please sign in to comment.