SanitizeGoIdentifier replaces illegal runes in the given string so that it is a valid Go identifier. Unlike SanitizeGoIdentity, it does not prefix reserved keywords or predeclared identifiers. This is useful for contexts where the name must be a valid identifier but is not used as a Go symbol (e.g.
(str string)
| 755 | // contexts where the name must be a valid identifier but is not used as a |
| 756 | // Go symbol (e.g. net/http ServeMux wildcard names). |
| 757 | func SanitizeGoIdentifier(str string) string { |
| 758 | sanitized := []rune(str) |
| 759 | |
| 760 | for i, c := range sanitized { |
| 761 | if !isValidRuneForGoID(i, c) { |
| 762 | sanitized[i] = '_' |
| 763 | } else { |
| 764 | sanitized[i] = c |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | return string(sanitized) |
| 769 | } |
| 770 | |
| 771 | // SanitizeGoIdentity deletes and replaces the illegal runes in the given |
| 772 | // string to use the string as a valid identity. It also prefixes reserved |
no test coverage detected