MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / SanitizeGoIdentity

Function SanitizeGoIdentity

pkg/codegen/utils.go:774–786  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

772// string to use the string as a valid identity. It also prefixes reserved
773// keywords and predeclared identifiers with an underscore.
774func 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

Callers 2

SanitizeEnumNamesFunction · 0.85
GenerateConstantsFunction · 0.85

Calls 4

SanitizeGoIdentifierFunction · 0.85
IsGoKeywordFunction · 0.85
IsValidGoIdentityFunction · 0.85

Tested by

no test coverage detected