Skip to content

Commit 92b6fba

Browse files
committed
added MatchedStrings
1 parent 852271a commit 92b6fba

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

internal/buffer/search.go

+10
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ func (b *Buffer) FindAllSubmatch(s string, start, end Loc) ([][]Loc, error) {
248248
return matches, err
249249
}
250250

251+
// MatchStrings converts a slice containing start and end positions of
252+
// matches or submatches to a slice containing the corresponding strings.
253+
func (b *Buffer) MatchedStrings(locs []Loc) ([]string) {
254+
strs := make([]string, len(locs)/2)
255+
for i := 0; 2*i < len(locs); i += 2 {
256+
strs[i]= string(b.Substr(locs[2*i], locs[2*i+1]))
257+
}
258+
return strs
259+
}
260+
251261
// FindNext finds the next occurrence of a given string in the buffer
252262
// It returns the start and end location of the match (if found) and
253263
// a boolean indicating if it was found

0 commit comments

Comments
 (0)