SanitizeGoIdentity deletes and replaces the illegal runes in the given string to use the string as a valid identity. It also prefixes reserved keywords and predeclared identifiers with an underscore.
(str string)
| 772 | // string to use the string as a valid identity. It also prefixes reserved |
| 773 | // keywords and predeclared identifiers with an underscore. |
| 774 | func SanitizeGoIdentity(str string) string { |
| 775 | str = SanitizeGoIdentifier(str) |
| 776 | |
| 777 | if IsGoKeyword(str) || IsPredeclaredGoIdentifier(str) { |
| 778 | str = "_" + str |
| 779 | } |
| 780 | |
| 781 | if !IsValidGoIdentity(str) { |
| 782 | panic("here is a bug") |
| 783 | } |
| 784 | |
| 785 | return str |
| 786 | } |
| 787 | |
| 788 | // SanitizeEnumNames fixes illegal chars in the enum names |
| 789 | // and removes duplicates |
no test coverage detected