MCPcopy Index your code
hub / github.com/cheat/cheat / Search

Method Search

internal/sheet/search.go:9–25  ·  view source on GitHub ↗

Search returns lines within a sheet's Text that match the search regex

(reg *regexp.Regexp)

Source from the content-addressed store, hash-verified

7
8// Search returns lines within a sheet's Text that match the search regex
9func (s *Sheet) Search(reg *regexp.Regexp) string {
10
11 // record matches
12 var matches []string
13
14 // search through the cheatsheet's text line by line
15 for _, line := range strings.Split(s.Text, "\n\n") {
16
17 // save matching lines
18 if reg.MatchString(line) {
19 matches = append(matches, line)
20 }
21 }
22
23 // Join matches with the same delimiter used for splitting
24 return strings.Join(matches, "\n\n")
25}

Callers 5

TestSearchNoMatchFunction · 0.95
TestSearchSingleMatchFunction · 0.95
TestSearchMultiMatchFunction · 0.95
FuzzSearchRegexFunction · 0.95
cmdSearchFunction · 0.80

Calls

no outgoing calls

Tested by 4

TestSearchNoMatchFunction · 0.76
TestSearchSingleMatchFunction · 0.76
TestSearchMultiMatchFunction · 0.76
FuzzSearchRegexFunction · 0.76