From 2072e3f88a190e3d74deb365f6ec2866964d181e Mon Sep 17 00:00:00 2001 From: Jens Gersdorf Date: Mon, 19 Jun 2023 09:24:50 +0200 Subject: [PATCH] [ENUMERATION] remove special character Minus => - should be mapped as _ --- gowsdl.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gowsdl.go b/gowsdl.go index cc340c4..8d8c77a 100644 --- a/gowsdl.go +++ b/gowsdl.go @@ -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 @@ -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 == '_' { @@ -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{