(name string, options *opts.Options)
| 17 | } |
| 18 | |
| 19 | func StructName(name string, options *opts.Options) string { |
| 20 | if rename := options.Rename[name]; rename != "" { |
| 21 | return rename |
| 22 | } |
| 23 | out := "" |
| 24 | name = strings.Map(func(r rune) rune { |
| 25 | if unicode.IsLetter(r) { |
| 26 | return r |
| 27 | } |
| 28 | if unicode.IsDigit(r) { |
| 29 | return r |
| 30 | } |
| 31 | return rune('_') |
| 32 | }, name) |
| 33 | |
| 34 | for _, p := range strings.Split(name, "_") { |
| 35 | if _, found := options.InitialismsMap[p]; found { |
| 36 | out += strings.ToUpper(p) |
| 37 | } else { |
| 38 | out += strings.Title(p) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // If a name has a digit as its first char, prepand an underscore to make it a valid Go name. |
| 43 | r, _ := utf8.DecodeRuneInString(out) |
| 44 | if unicode.IsDigit(r) { |
| 45 | return "_" + out |
| 46 | } else { |
| 47 | return out |
| 48 | } |
| 49 | } |
no outgoing calls
no test coverage detected