-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparser_helpers.go
More file actions
51 lines (44 loc) · 1022 Bytes
/
parser_helpers.go
File metadata and controls
51 lines (44 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package codescan
import (
"strings"
)
// a shared function that can be used to split given headers
// into a title and description.
func collectScannerTitleDescription(headers []string) (title, desc []string) {
hdrs := cleanupScannerLines(headers, rxUncommentHeaders)
idx := -1
for i, line := range hdrs {
if strings.TrimSpace(line) == "" {
idx = i
break
}
}
if idx > -1 {
title = hdrs[:idx]
if len(title) > 0 {
title[0] = rxTitleStart.ReplaceAllString(title[0], "")
}
if len(hdrs) > idx+1 {
desc = hdrs[idx+1:]
} else {
desc = nil
}
return title, desc
}
if len(hdrs) > 0 {
line := hdrs[0]
switch {
case rxPunctuationEnd.MatchString(line):
title = []string{line}
desc = hdrs[1:]
case rxTitleStart.MatchString(line):
title = []string{rxTitleStart.ReplaceAllString(line, "")}
desc = hdrs[1:]
default:
desc = hdrs
}
}
return title, desc
}