Skip to content

Commit

Permalink
Merge pull request #255 from jens1205/enumeration
Browse files Browse the repository at this point in the history
Enumeration duplicates with special characters like "+"
  • Loading branch information
c4milo authored Aug 13, 2023
2 parents 607a639 + 2072e3f commit a328891
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit a328891

Please sign in to comment.