-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplacement.go
91 lines (84 loc) · 1.04 KB
/
replacement.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package generator
import "github.com/iancoleman/strcase"
var reservedWords = []string{
"abstract",
"else",
"import",
"show",
"as",
"enum",
"in",
"static",
"assert",
"export",
"interface",
"super",
"async",
"extends",
"is",
"switch",
"await",
"3",
"extension",
"late",
"sync",
"break",
"external",
"library",
"this",
"case",
"factory",
"mixin",
"throw",
"catch",
"false",
"new",
"true",
"class",
"final",
"null",
"try",
"const",
"finally",
"on",
"typedef",
"continue",
"for",
"operator",
"var",
"covariant",
"Function",
"part",
"void",
"default",
"get",
"required",
"while",
"deferred",
"hide",
"rethrow",
"with",
"do",
"if",
"return",
"yield",
"dynamic",
"implements",
"set",
}
func isReserved(n string) bool {
for _, s := range reservedWords {
if s == n {
return true
}
}
return false
}
// ReplaceFieldName a field name with a non-reserved name
func ReplaceFieldName(name string) string {
name = strcase.ToLowerCamel(name)
if isReserved(name) {
return name + "_"
}
return name
}