MCPcopy Index your code
hub / github.com/nikivdev/go / parseSections

Function parseSections

cli/spec/main.go:1012–1043  ·  view source on GitHub ↗
(content string)

Source from the content-addressed store, hash-verified

1010}
1011
1012func parseSections(content string) map[string]section {
1013 result := make(map[string]section)
1014 lines := strings.Split(content, "\n")
1015 re := regexp.MustCompile(`^##\s+(.+)$`)
1016
1017 var currentTitle string
1018 var currentBody bytes.Buffer
1019 flush := func() {
1020 if currentTitle == "" {
1021 return
1022 }
1023 result[currentTitle] = section{Title: currentTitle, Content: strings.TrimSpace(currentBody.String())}
1024 currentBody.Reset()
1025 }
1026
1027 for _, raw := range lines {
1028 line := strings.TrimRight(raw, "\r")
1029 if m := re.FindStringSubmatch(strings.TrimSpace(line)); m != nil {
1030 flush()
1031 currentTitle = strings.TrimSpace(m[1])
1032 continue
1033 }
1034
1035 if currentTitle != "" {
1036 currentBody.WriteString(line)
1037 currentBody.WriteByte('\n')
1038 }
1039 }
1040 flush()
1041
1042 return result
1043}
1044
1045func prioritizedSections(sections map[string]section) []section {
1046 if len(sections) == 0 {

Callers 1

buildPromptBundleFunction · 0.85

Calls 1

StringMethod · 0.80

Tested by

no test coverage detected