-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelm_util.go
39 lines (33 loc) · 903 Bytes
/
elm_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import "strings"
func precedence(s string) string {
if strings.ContainsRune(s, ' ') {
return "(" + s + ")"
}
return s
}
func splitTypeNamePair(s string) (string, string) {
els := strings.Split(s, ":")
goName := els[0]
elmName := goName
if len(els) > 1 {
elmName = els[1]
}
return goName, elmName
}
// TypeNamePairs maps the source Go type name to the target Elm type name.
type TypeNamePairs map[string]string
// Add splits the input string on : and updates the map.
func (m TypeNamePairs) Add(s string) {
goName, elmName := splitTypeNamePair(s)
m[goName] = elmName
}
// ElmName returns the Elm record name for a Go struct type.
func (m TypeNamePairs) ElmName(typeName string) string {
recordName := m[typeName]
if recordName == "" {
camelCaseName := camelCase(typeName)
recordName = strings.ToUpper(camelCaseName[:1]) + camelCaseName[1:]
}
return recordName
}