github.com/go-swagger/go-swagger@v0.31.0/codescan/parser_helpers.go (about)

     1  package codescan
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // a shared function that can be used to split given headers
     8  // into a title and description
     9  func collectScannerTitleDescription(headers []string) (title, desc []string) {
    10  	hdrs := cleanupScannerLines(headers, rxUncommentHeaders, nil)
    11  
    12  	idx := -1
    13  	for i, line := range hdrs {
    14  		if strings.TrimSpace(line) == "" {
    15  			idx = i
    16  			break
    17  		}
    18  	}
    19  
    20  	if idx > -1 {
    21  		title = hdrs[:idx]
    22  		if len(title) > 0 {
    23  			title[0] = rxTitleStart.ReplaceAllString(title[0], "")
    24  		}
    25  		if len(hdrs) > idx+1 {
    26  			desc = hdrs[idx+1:]
    27  		} else {
    28  			desc = nil
    29  		}
    30  		return
    31  	}
    32  
    33  	if len(hdrs) > 0 {
    34  		line := hdrs[0]
    35  		switch {
    36  		case rxPunctuationEnd.MatchString(line):
    37  			title = []string{line}
    38  			desc = hdrs[1:]
    39  		case rxTitleStart.MatchString(line):
    40  			title = []string{rxTitleStart.ReplaceAllString(line, "")}
    41  			desc = hdrs[1:]
    42  		default:
    43  			desc = hdrs
    44  		}
    45  	}
    46  
    47  	return
    48  }