Documentation
¶
Index ¶
- func IsLiteral(s string) bool
- type Config
- type LiteralMatcher
- func (m *LiteralMatcher) CaseFold() bool
- func (m *LiteralMatcher) Expand(dst []byte, template []byte, line []byte, locs []int) []byte
- func (m *LiteralMatcher) FindAll(data []byte, callback func(locs []int) bool)
- func (m *LiteralMatcher) Literal() []byte
- func (m *LiteralMatcher) Literals() [][]byte
- func (m *LiteralMatcher) Match(line []byte) (locs []int, ok bool)
- func (m *LiteralMatcher) MatchFile(data []byte) bool
- func (m *LiteralMatcher) Name() string
- type Matcher
- type PCREMatcher
- func (m *PCREMatcher) Expand(dst []byte, template []byte, line []byte, locs []int) []byte
- func (m *PCREMatcher) FindAll(data []byte, callback func(locs []int) bool)
- func (m *PCREMatcher) Literal() []byte
- func (m *PCREMatcher) Literals() [][]byte
- func (m *PCREMatcher) Match(line []byte) (locs []int, ok bool)
- func (m *PCREMatcher) MatchFile(data []byte) bool
- func (m *PCREMatcher) Name() string
- type RegexMatcher
- func (m *RegexMatcher) Expand(dst []byte, template []byte, line []byte, locs []int) []byte
- func (m *RegexMatcher) FindAll(data []byte, callback func(locs []int) bool)
- func (m *RegexMatcher) Literal() []byte
- func (m *RegexMatcher) Literals() [][]byte
- func (m *RegexMatcher) Match(line []byte) (locs []int, ok bool)
- func (m *RegexMatcher) MatchFile(data []byte) bool
- func (m *RegexMatcher) Name() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Pattern is the search string or regex.
Pattern string
// FixedStrings treats the pattern as a literal string.
FixedStrings bool
// IgnoreCase makes matching case-insensitive.
IgnoreCase bool
// SmartCase makes matching case-insensitive unless the pattern
// contains uppercase characters.
SmartCase bool
// Pcre2 uses PCRE2-compatible regex engine.
Pcre2 bool
// Multiline enables matching across line boundaries.
Multiline bool
// WordRegexp matches only if the match is surrounded by word boundaries.
WordRegexp bool
}
Config holds pattern matching options.
type LiteralMatcher ¶
type LiteralMatcher struct {
// contains filtered or unexported fields
}
LiteralMatcher uses byte search for fixed-string matching. It is significantly faster than RegexMatcher for simple patterns. Users should generally create Matchers via New().
func (*LiteralMatcher) CaseFold ¶
func (m *LiteralMatcher) CaseFold() bool
CaseFold returns true if this matcher performs case-insensitive matching.
func (*LiteralMatcher) FindAll ¶
func (m *LiteralMatcher) FindAll(data []byte, callback func(locs []int) bool)
FindAll searches for all matches in the data and calls the callback for each.
func (*LiteralMatcher) Literal ¶
func (m *LiteralMatcher) Literal() []byte
Literal returns the fixed literal string if the matcher is purely literal and case-sensitive.
func (*LiteralMatcher) Literals ¶
func (m *LiteralMatcher) Literals() [][]byte
Literals returns the literal as a single-element slice, or nil if case-insensitive (AC can't cheaply handle case-folded matching).
func (*LiteralMatcher) Match ¶
func (m *LiteralMatcher) Match(line []byte) (locs []int, ok bool)
Match searches for the pattern in a single line.
func (*LiteralMatcher) MatchFile ¶
func (m *LiteralMatcher) MatchFile(data []byte) bool
MatchFile searches the entire file contents for the pattern.
type Matcher ¶
type Matcher interface {
// Match searches for the pattern in a single line.
// Returns the byte offsets of the match and all capture groups.
// locs[0]:locs[1] is the full match, locs[2]:locs[3] is group 1, etc.
// The caller MUST NOT retain the locs slice after the call.
Match(line []byte) (locs []int, ok bool)
// MatchFile searches the entire file contents for the pattern.
MatchFile(data []byte) bool
// Name returns the matcher implementation name ("literal", "regex", or "pcre").
Name() string
// Literal returns the fixed literal string if the matcher is purely literal,
// or an empty slice if it's a regex. This allows for fast pre-filtering.
Literal() []byte
// Literals returns all mandatory literal strings for multi-pattern
// pre-filtering (e.g., Aho-Corasick). Returns nil if extraction is not
// possible (regex metacharacters, case-insensitive without a clean set, etc.).
// When non-nil, every byte slice must appear in the data for a match to be
// possible. Used by the search pre-filter to skip files early.
Literals() [][]byte
// FindAll searches for all matches in the data and calls the callback for each.
// The callback returns false to stop searching.
FindAll(data []byte, callback func(locs []int) bool)
// Expand appends the replacement template to dst, replacing placeholders
// like $1 or ${name} with captured groups from the match.
Expand(dst []byte, template []byte, line []byte, locs []int) []byte
}
Matcher performs line-oriented matching.
type PCREMatcher ¶
type PCREMatcher struct {
// contains filtered or unexported fields
}
PCREMatcher wraps regexp2 for PCRE2-compatible pattern matching. Users should generally create Matchers via New().
func (*PCREMatcher) FindAll ¶
func (m *PCREMatcher) FindAll(data []byte, callback func(locs []int) bool)
FindAll searches for all matches in the data and calls the callback for each.
func (*PCREMatcher) Literal ¶
func (m *PCREMatcher) Literal() []byte
func (*PCREMatcher) Literals ¶
func (m *PCREMatcher) Literals() [][]byte
Literals extracts literals from simple alternation patterns.
func (*PCREMatcher) Match ¶
func (m *PCREMatcher) Match(line []byte) (locs []int, ok bool)
Match searches for the pattern in a single line.
func (*PCREMatcher) MatchFile ¶
func (m *PCREMatcher) MatchFile(data []byte) bool
MatchFile searches the entire file contents for the pattern.
type RegexMatcher ¶
type RegexMatcher struct {
// contains filtered or unexported fields
}
RegexMatcher wraps stdlib regexp for pattern matching. Users should generally create Matchers via New().
func (*RegexMatcher) FindAll ¶
func (m *RegexMatcher) FindAll(data []byte, callback func(locs []int) bool)
FindAll searches for all matches in the data and calls the callback for each.
func (*RegexMatcher) Literal ¶
func (m *RegexMatcher) Literal() []byte
func (*RegexMatcher) Literals ¶
func (m *RegexMatcher) Literals() [][]byte
Literals extracts mandatory literals from simple alternation patterns like (foo|bar|baz). Returns nil for non-alternation regexes or case-insensitive patterns where Literal() already has a prefix.
func (*RegexMatcher) Match ¶
func (m *RegexMatcher) Match(line []byte) (locs []int, ok bool)
Match searches for the pattern in a single line.
func (*RegexMatcher) MatchFile ¶
func (m *RegexMatcher) MatchFile(data []byte) bool
MatchFile searches the entire file contents for the pattern.