Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeData ¶
DecodeData transcode raw file data to UTF-8 based on the configured encoding name. If encoding is empty or "auto", it sniffs for UTF-16LE, UTF-16BE, or UTF-8 BOMs. Returns the decoded data, a boolean indicating whether data was modified/copied, and any error.
func LookupEncoding ¶
LookupEncoding resolves an encoding name to a supported encoding.Encoding. Case-insensitive, supporting common aliases (e.g. "utf-16le", "latin1", "windows-1252"). Special names: - "" or "auto": returns (nil, nil) indicating automatic BOM sniffing. - "none", "binary", "raw": returns (encoding.Nop, nil) indicating raw byte scanning without BOM sniffing.
Types ¶
type Config ¶
type Config struct {
// MaxCount limits matches per file. 0 means unlimited.
MaxCount int
// Before is the number of context lines before each match.
Before int
// After is the number of context lines after each match.
After int
// SearchBinary includes binary files in results.
SearchBinary bool
// OnlyBinary restricts results to binary files only.
OnlyBinary bool
// MmapThreshold is the minimum file size in bytes that triggers mmap
// instead of a full read. 0 defaults to 128KB.
MmapThreshold int64
// Multiline enables matching across line boundaries.
Multiline bool
// OnlyMatching returns only the matched parts of a line.
OnlyMatching bool
// Replace is the replacement template.
Replace string
// Encoding specifies the text encoding (e.g. "auto", "utf-16le", "latin1", "none").
// Empty string or "auto" enables automatic UTF-16/UTF-8 BOM sniffing.
Encoding string
}
Config holds search behavior options.
type Entry ¶
type Entry struct {
// Kind is either EntryMatch or EntryContext.
Kind EntryKind
// Line is the 1-based line number.
Line int
// LineBytes is the full line content.
LineBytes []byte
// Column is the 1-based byte offset of the match start.
// 0 for context lines.
Column int
}
Entry is an ordered output line — either a match or context.
type Match ¶
type Match struct {
// Line is the 1-based line number.
Line int
// Column is the 1-based byte offset of the match start.
Column int
// LineBytes is the full line content.
LineBytes []byte
// Submatches holds [start, end) byte offsets for each submatch.
Submatches [][2]int
// ReplaceBytes holds the expanded replacement if requested.
ReplaceBytes []byte
}
Match represents a single match within a line.
type Result ¶
type Result struct {
// Path is the file path.
Path string
// Matches is the list of matches found in the file.
Matches []Match
// Entries is the ordered list of match and context entries.
// Only populated if context lines are requested.
Entries []Entry
// Binary is true if the file was detected as binary.
Binary bool
// ModTime is the file's last modification time.
ModTime time.Time
// CreatedAt is the file's birth time (creation time).
CreatedAt time.Time
// AccessedAt is the file's last access time.
AccessedAt time.Time
// Error is any error encountered while searching this file.
Error error
}
Result holds all matches for a single file.
type Searcher ¶
type Searcher struct {
// contains filtered or unexported fields
}
Searcher scans files for matches against a compiled pattern.
func NewSearcher ¶
NewSearcher creates a searcher with the given config and matcher. If fsys is nil, it defaults to the local OS filesystem.
func (*Searcher) Search ¶
Search reads a file via the provided fsref.Ref and returns all matches. When context lines are requested, a ring buffer retains only the last <before> lines, avoiding O(N) memory for large files with few matches.
func (*Searcher) SearchBytes ¶
SearchBytes scans an in-memory byte slice for matches without accessing any filesystem.
func (*Searcher) SearchPath ¶
SearchPath is a compatibility shim that creates a pathRef and calls Search.