MCPcopy Create free account
hub / github.com/dim-an/cod / FindIndentedParagraph

Method FindIndentedParagraph

parse_doc/textutil.go:101–133  ·  view source on GitHub ↗
(pattern string, startLine int)

Source from the content-addressed store, hash-verified

99}
100
101func (pt *preparedText) FindIndentedParagraph(pattern string, startLine int) *lineTree {
102 var cur int
103 var extractTree func() lineTree
104 extractTree = func() (res lineTree) {
105 res = lineTree{
106 line: pt.lines[cur],
107 lineBegin: cur,
108 lineEnd: cur,
109 children: nil,
110 }
111 startIndent := computeIndent(pt.lines[cur])
112 for cur++; cur < len(pt.lines); {
113 curIndent := computeIndent(pt.lines[cur])
114 if curIndent > startIndent {
115 res.children = append(res.children, extractTree())
116 } else {
117 break
118 }
119 }
120 res.lineEnd = cur
121 return
122 }
123
124 cur = startLine
125 for ; cur < len(pt.lines); cur++ {
126 if strings.Contains(pt.lines[cur], pattern) {
127 res := extractTree()
128 return &res
129 }
130 }
131
132 return nil
133}
134
135// Compute line indent.
136// Return -1 if line is visibly empty.

Callers 2

ParseMethod · 0.80

Calls 1

computeIndentFunction · 0.85

Tested by 1