Documentation
¶
Overview ¶
Package search searches plain-text data sets for lines.
During tests, can be used the next tags:
-tags=debug Show data used at case of failure.
== TODO
Add function to get several lines, from start to end
func Lines(start, end int) (string, error)
Index ¶
- func CountLines(filename string, src []byte) (n int, err error)
- type ModeSearch
- type Searcher
- func (se *Searcher) Close() error
- func (se *Searcher) Contains(s string, mode ModeSearch) (found bool, err error)
- func (se *Searcher) Count(s string, mode ModeSearch) (n int, err error)
- func (se *Searcher) CountLines() (n int, err error)
- func (se *Searcher) HasPrefix(s string, mode ModeSearch) (found bool, err error)
- func (se *Searcher) HasSuffix(s string, mode ModeSearch) (found bool, err error)
- func (se *Searcher) Line(n int) (string, error)
- func (se *Searcher) LineMatched(w WhichLine) (string, error)
- func (se *Searcher) Pos() (start, end int64)
- type WhichLine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ModeSearch ¶
type ModeSearch int8
A ModeSearch value is a set of flags (or 0) to control behavior at searching.
const ( // Ignore case distinctions. ModIgnoreCase ModeSearch = 1 << iota // Skip skip lines that start with the comment string and remove both spaces // and tabulations at the beginning to math the comment string. ModSkipComment // Removes all leading and trailing white spaces. ModTrimSpace )
Modes used to search.
type Searcher ¶
type Searcher struct {
// contains filtered or unexported fields
}
Searcher represents the file or data where search plain-text.
func NewSearcher ¶
func NewSearcher(filename string, src []byte, comment string, mode ModeSearch, ) (se *Searcher, err error)
NewSearcher prepares the 'Searcher' for a file at 'filename' or data at 'src'. If 'filename == ""', uses 'src'.
Must use 'Close()' to close the file.
func (*Searcher) Contains ¶
func (se *Searcher) Contains(s string, mode ModeSearch) (found bool, err error)
Contains reports whether the file contains 's'.
If 'mod < 0', uses the mode set at 'Searcher'. The modes allowed are 'ModIgnoreCase', 'ModSkipComment' and 'ModTrimSpace'.
func (*Searcher) Count ¶
func (se *Searcher) Count(s string, mode ModeSearch) (n int, err error)
Count returns the number of matching lines.
The modes allowed are 'ModIgnoreCase' and 'ModSkipComment'. If 'mode < 0', uses the mode set at 'Searcher'.
func (*Searcher) CountLines ¶ added in v1.0.2
CountLines returns the number of total lines.
func (*Searcher) HasPrefix ¶
func (se *Searcher) HasPrefix(s string, mode ModeSearch) (found bool, err error)
HasPrefix reports whether the file has a line that begins with 's'.
If 'mod < 0', uses the mode set at 'Searcher'. The modes allowed are 'ModIgnoreCase', 'ModSkipComment' and 'ModTrimSpace'.
func (*Searcher) HasSuffix ¶
func (se *Searcher) HasSuffix(s string, mode ModeSearch) (found bool, err error)
HasSuffix reports whether the file has a line that ends with 's'.
If 'mod < 0', uses the mode set at 'Searcher'. The modes allowed are 'ModIgnoreCase', 'ModSkipComment' and 'ModTrimSpace'.
func (*Searcher) Line ¶
Line returns the line indicated according to the value of n:
if 'n == 0', returns an empty string if 'n > 0', searchs from start if 'n < 0', searchs from end.
Do not add the character of new line ('\n') at the end of the line returned. If the last line (-1) is '\n', then it returns the anterior one.
func (*Searcher) LineMatched ¶
LineMatched returns the line indicated by 'WhichLine'.
Must be called after of functions that search text into a line: 'Contains', 'HasPrefix' and 'HasSuffix'.