Skip to content

Commit

Permalink
[ENUMERATION] remove special character Minus => - should be mapped as _
Browse files Browse the repository at this point in the history
  • Loading branch information
jgersdorf committed Jun 19, 2023
1 parent f362b32 commit 2072e3f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,7 @@ var reservedWordsInAttr = map[string]string{

var specialCharacterMapping = map[string]string{
"+": "Plus",
"-": "Minus",
"@": "At",
"/": "Slash",
"$": "Dollar",
}

// Replaces Go reserved keywords to avoid compilation issues
Expand All @@ -484,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 @@ -494,15 +495,11 @@ func normalize(value string) string {
return -1
}

for k, v := range specialCharacterMapping {
value = strings.ReplaceAll(value, k, v)
}

return strings.Map(mapping, value)
}

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 2072e3f

Please sign in to comment.