MCPcopy Create free account
hub / github.com/cel-expr/cel-go / ParseDescriptions

Function ParseDescriptions

common/doc.go:94–118  ·  view source on GitHub ↗

ParseDescriptions splits a documentation string into multiple multi-line description sections, using blank lines as delimiters.

(doc string)

Source from the content-addressed store, hash-verified

92// ParseDescriptions splits a documentation string into multiple multi-line description
93// sections, using blank lines as delimiters.
94func ParseDescriptions(doc string) []string {
95 var examples []string
96 if len(doc) != 0 {
97 lines := strings.Split(doc, "\n")
98 lineStart := 0
99 for i, l := range lines {
100 // Trim trailing whitespace to identify effectively blank lines.
101 l = strings.TrimRightFunc(l, unicode.IsSpace)
102 // If a line is blank, it marks the end of the current section.
103 if len(l) == 0 {
104 // Start the next section after the blank line.
105 ex := lines[lineStart:i]
106 if len(ex) != 0 {
107 examples = append(examples, MultilineDescription(ex...))
108 }
109 lineStart = i + 1
110 }
111 }
112 // Append the last section if it wasn't terminated by a blank line.
113 if lineStart < len(lines) {
114 examples = append(examples, MultilineDescription(lines[lineStart:]...))
115 }
116 }
117 return examples
118}
119
120// NewVariableDoc creates a new Doc struct specifically for documenting a variable.
121func NewVariableDoc(name, celType, description string) *Doc {

Callers 2

ExamplesMethod · 0.92
TestParseDescriptionsFunction · 0.85

Calls 1

MultilineDescriptionFunction · 0.85

Tested by 1

TestParseDescriptionsFunction · 0.68