2019-10-20 16:02:28 +02:00
|
|
|
package sheet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-02-15 20:40:33 +01:00
|
|
|
// Search returns lines within a sheet's Text that match the search regex
|
|
|
|
func (s *Sheet) Search(reg *regexp.Regexp) string {
|
2019-10-20 16:02:28 +02:00
|
|
|
|
|
|
|
// record matches
|
2020-02-15 21:56:25 +01:00
|
|
|
matches := ""
|
2019-10-20 16:02:28 +02:00
|
|
|
|
|
|
|
// search through the cheatsheet's text line by line
|
2020-02-15 21:56:25 +01:00
|
|
|
for _, line := range strings.Split(s.Text, "\n\n") {
|
2019-10-20 16:02:28 +02:00
|
|
|
|
|
|
|
// exit early if the line doesn't match the regex
|
2020-02-15 21:56:25 +01:00
|
|
|
if reg.MatchString(line) {
|
|
|
|
matches += line + "\n\n"
|
2019-10-20 16:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:56:25 +01:00
|
|
|
return strings.TrimSpace(matches)
|
2019-10-20 16:02:28 +02:00
|
|
|
}
|