MCPcopy
hub / github.com/micro-editor/micro / FindNext

Method FindNext

internal/buffer/search.go:154–190  ·  view source on GitHub ↗

FindNext finds the next occurrence of a given string in the buffer It returns the start and end location of the match (if found) and a boolean indicating if it was found May also return an error if the search regex is invalid

(s string, start, end, from Loc, down bool, useRegex bool)

Source from the content-addressed store, hash-verified

152// a boolean indicating if it was found
153// May also return an error if the search regex is invalid
154func (b *Buffer) FindNext(s string, start, end, from Loc, down bool, useRegex bool) ([2]Loc, bool, error) {
155 if s == "" {
156 return [2]Loc{}, false, nil
157 }
158
159 var r *regexp.Regexp
160 var err error
161
162 if !useRegex {
163 s = regexp.QuoteMeta(s)
164 }
165
166 if b.Settings["ignorecase"].(bool) {
167 r, err = regexp.Compile("(?i)" + s)
168 } else {
169 r, err = regexp.Compile(s)
170 }
171
172 if err != nil {
173 return [2]Loc{}, false, err
174 }
175
176 var found bool
177 var l [2]Loc
178 if down {
179 l, found = b.findDown(r, from, end)
180 if !found {
181 l, found = b.findDown(r, start, end)
182 }
183 } else {
184 l, found = b.findUp(r, from, start)
185 if !found {
186 l, found = b.findUp(r, end, start)
187 }
188 }
189 return l, found, nil
190}
191
192// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
193// and returns the number of replacements made and the number of characters

Callers 2

SearchMatchMethod · 0.45
NewBufferFunction · 0.45

Calls 2

findDownMethod · 0.95
findUpMethod · 0.95

Tested by

no test coverage detected