Skip to content

Commit

Permalink
fix new split function for go 1.12
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Porto Carrero <[email protected]>
  • Loading branch information
casualjim committed Jun 16, 2019
1 parent 90753eb commit de205c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 15 additions & 1 deletion name_lexem.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package swag

import "unicode"

type (
nameLexem interface {
GetUnsafeGoName() string
Expand Down Expand Up @@ -49,8 +51,20 @@ func (l *initialismNameLexem) GetUnsafeGoName() string {
}

func (l *casualNameLexem) GetUnsafeGoName() string {
var first rune
var rest string
for i, orig := range l.original {
if i == 0 {
first = orig
continue
}
if i > 0 {
rest = l.original[i:]
break
}
}
if len(l.original) > 1 {
return upper(l.original[:1]) + lower(l.original[1:])
return string(unicode.ToUpper(first)) + lower(rest)
}

return l.original
Expand Down
10 changes: 5 additions & 5 deletions split.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func (s *splitter) breakCasualString(str []rune) []nameLexem {
addCasualNameLexem(original)
}

for _, rune := range string(str) {
if replace, found := nameReplaceTable[rune]; found {
for _, rn := range string(str) {
if replace, found := nameReplaceTable[rn]; found {
if currentSegment != "" {
addNameLexem(currentSegment)
currentSegment = ""
Expand All @@ -235,7 +235,7 @@ func (s *splitter) breakCasualString(str []rune) []nameLexem {
continue
}

if !unicode.In(rune, unicode.L, unicode.M, unicode.N, unicode.Pc) {
if !unicode.In(rn, unicode.L, unicode.M, unicode.N, unicode.Pc) {
if currentSegment != "" {
addNameLexem(currentSegment)
currentSegment = ""
Expand All @@ -244,14 +244,14 @@ func (s *splitter) breakCasualString(str []rune) []nameLexem {
continue
}

if unicode.IsUpper(rune) {
if unicode.IsUpper(rn) {
if currentSegment != "" {
addNameLexem(currentSegment)
}
currentSegment = ""
}

currentSegment += string(rune)
currentSegment += string(rn)
}

if currentSegment != "" {
Expand Down

0 comments on commit de205c6

Please sign in to comment.