X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=binapigen%2Fstrings.go;fp=binapigen%2Fdefinitions.go;h=1ab24e9bd221a8138817cc4777e48195b25e7673;hb=58da9ac6e691a8c660eb8ca838a154e11da0db68;hp=3c8a87449f3c3094af99b859772c2022db4c2b78;hpb=a155cd438c6558da266c1c5931361ea088b35653;p=govpp.git diff --git a/binapigen/definitions.go b/binapigen/strings.go similarity index 92% rename from binapigen/definitions.go rename to binapigen/strings.go index 3c8a874..1ab24e9 100644 --- a/binapigen/definitions.go +++ b/binapigen/strings.go @@ -15,8 +15,10 @@ package binapigen import ( + "go/token" "strings" "unicode" + "unicode/utf8" ) // commonInitialisms is a set of common initialisms that need to stay in upper case. @@ -74,7 +76,8 @@ var specialInitialisms = map[string]string{ } func usesInitialism(s string) string { - if u := strings.ToUpper(s); commonInitialisms[u] { + u := strings.ToUpper(s) + if commonInitialisms[u] { return u } else if su, ok := specialInitialisms[u]; ok { return su @@ -151,3 +154,12 @@ func camelCaseName(name string) (should string) { } return string(runes) } + +// sanitizedName returns the string converted into a valid Go identifier. +func sanitizedName(s string) string { + r, _ := utf8.DecodeRuneInString(s) + if token.Lookup(s).IsKeyword() || !unicode.IsLetter(r) { + return s + "s" + } + return s +}