Skip to content

Commit a328891

Browse files
authored
Merge pull request #255 from jens1205/enumeration
Enumeration duplicates with special characters like "+"
2 parents 607a639 + 2072e3f commit a328891

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

gowsdl.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ var reservedWordsInAttr = map[string]string{
456456
"string": "astring",
457457
}
458458

459+
var specialCharacterMapping = map[string]string{
460+
"+": "Plus",
461+
"@": "At",
462+
}
463+
459464
// Replaces Go reserved keywords to avoid compilation issues
460465
func replaceReservedWords(identifier string) string {
461466
value := reservedWords[identifier]
@@ -476,8 +481,12 @@ func replaceAttrReservedWords(identifier string) string {
476481

477482
// Normalizes value to be used as a valid Go identifier, avoiding compilation issues
478483
func normalize(value string) string {
484+
for k, v := range specialCharacterMapping {
485+
value = strings.ReplaceAll(value, k, v)
486+
}
487+
479488
mapping := func(r rune) rune {
480-
if r == '.' {
489+
if r == '.' || r == '-' {
481490
return '_'
482491
}
483492
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {
@@ -490,7 +499,7 @@ func normalize(value string) string {
490499
}
491500

492501
func goString(s string) string {
493-
return strings.Replace(s, "\"", "\\\"", -1)
502+
return strings.ReplaceAll(s, "\"", "\\\"")
494503
}
495504

496505
var xsd2GoTypes = map[string]string{

0 commit comments

Comments
 (0)