Documentation ¶
Overview ¶
Package grep allows find text at files.
== TODO
Add function to get several lines, from start to end
func Lines(start, end int) (string, error)
Index ¶
- type Finder
- func (fi *Finder) Close() error
- func (fi *Finder) Contains(s string, mode ModeFind) (found bool, err error)
- func (fi *Finder) Count(s string, mode ModeFind) (n int, err error)
- func (fi *Finder) HasPrefix(s string, mode ModeFind) (found bool, err error)
- func (fi *Finder) HasSuffix(s string, mode ModeFind) (found bool, err error)
- func (fi *Finder) Line(n int) (string, error)
- func (fi *Finder) LineMatched(p LinePlace) (string, error)
- func (fi *Finder) Pos() (start, end int64)
- type LinePlace
- type ModeFind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
Finder represents the file or data where find a string or line.
func NewFromFile ¶ added in v1.1.0
New prepares the 'Finder' via the `filename`. Must use `Close()` to close the file.
func (*Finder) Contains ¶
Contains reports whether the file contains `s`. If `mod < 0`, uses the mode set at 'Finder'.
The modes allowed are `ModIgnoreCase`, `ModSkipComment` and `ModTrimSpace`.
func (*Finder) Count ¶
Count returns the number of matching lines. If `mod < 0`, uses the mode set at 'Finder'.
The modes allowed are `ModIgnoreCase` and `ModSkipComment`.
func (*Finder) HasPrefix ¶
HasPrefix reports whether the file has a line that begins with `s`. If `mod < 0`, uses the mode set at 'Finder'.
The modes allowed are `ModIgnoreCase`, `ModSkipComment` and `ModTrimSpace`.
func (*Finder) HasSuffix ¶
HasSuffix reports whether the file has a line that ends with `s`. If `mod < 0`, uses the mode set at 'Finder'.
The modes allowed are `ModIgnoreCase`, `ModSkipComment` and `ModTrimSpace`.
func (*Finder) Line ¶
Line returns the line indicated according to the value of n:
if 'n == 0', returns an empty string if 'n > 0', finds from start if 'n < 0', finds 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 (*Finder) LineMatched ¶
LineMatched returns the line indicated by `LinePlace`.
Must be called after of functions that find text into a line: `Contains`, `HasPrefix` and `HasSuffix`.
type ModeFind ¶
type ModeFind int8
A ModeFind value is a set of flags (or 0) to control behavior at find into a file.
const ( // Ignore case distinctions. ModIgnoreCase ModeFind = 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 find into a file.