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

Function SanitizeGoIdentifier

pkg/codegen/utils.go:757–769  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
757func 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

Callers 3

SwaggerUriToStdHttpUriFunction · 0.85
SanitizeGoIdentityFunction · 0.85
SanitizedParamNameMethod · 0.85

Calls 1

isValidRuneForGoIDFunction · 0.85

Tested by

no test coverage detected