Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration duplicates with special characters like "+" #255

Merged
merged 3 commits into from
Aug 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ var reservedWordsInAttr = map[string]string{
"string": "astring",
}

var specialCharacterMapping = map[string]string{
"+": "Plus",
"@": "At",
}

// Replaces Go reserved keywords to avoid compilation issues
func replaceReservedWords(identifier string) string {
value := reservedWords[identifier]
Expand All @@ -476,8 +481,12 @@ func replaceAttrReservedWords(identifier string) string {

// Normalizes value to be used as a valid Go identifier, avoiding compilation issues
func normalize(value string) string {
for k, v := range specialCharacterMapping {
value = strings.ReplaceAll(value, k, v)
}

mapping := func(r rune) rune {
if r == '.' {
if r == '.' || r == '-' {
return '_'
}
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {
Expand All @@ -490,7 +499,7 @@ func normalize(value string) string {
}

func goString(s string) string {
return strings.Replace(s, "\"", "\\\"", -1)
return strings.ReplaceAll(s, "\"", "\\\"")
}

var xsd2GoTypes = map[string]string{
Expand Down