github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/codescan/parser_helpers_go118.go (about) 1 //go:build !go1.19 2 // +build !go1.19 3 4 package codescan 5 6 import "strings" 7 8 // a shared function that can be used to split given headers 9 // into a title and description 10 func collectScannerTitleDescription(headers []string) (title, desc []string) { 11 hdrs := cleanupScannerLines(headers, rxUncommentHeaders, nil) 12 13 idx := -1 14 for i, line := range hdrs { 15 if strings.TrimSpace(line) == "" { 16 idx = i 17 break 18 } 19 } 20 21 if idx > -1 { 22 title = hdrs[:idx] 23 if len(hdrs) > idx+1 { 24 desc = hdrs[idx+1:] 25 } else { 26 desc = nil 27 } 28 return 29 } 30 31 if len(hdrs) > 0 { 32 line := hdrs[0] 33 if rxPunctuationEnd.MatchString(line) { 34 title = []string{line} 35 desc = hdrs[1:] 36 } else { 37 desc = hdrs 38 } 39 } 40 41 return 42 }