| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package executor
- import (
- "fmt"
- "regexp"
- "strings"
- schemepkg "git.buran.team/main/cep/scheme"
- )
- type MatchProcessor struct {
- expression *regexp.Regexp
- count int
- }
- func NewMatchProcessor(processorScheme schemepkg.Processor) (*MatchProcessor, error) {
- e, err := regexp.Compile(processorScheme.KindMatch.Expression)
- if err != nil {
- return nil, fmt.Errorf("can't create match processor: %w", err)
- }
- return &MatchProcessor{
- expression: e,
- count: processorScheme.KindMatch.Count,
- }, nil
- }
- func (this *MatchProcessor) Process(buffer []byte) bool {
- lines := strings.Split(string(buffer), "\n")
- count := 0
- for _, line := range lines {
- if !this.expression.Match([]byte(line)) {
- continue
- }
- count += 1
- }
- if this.count == -1 {
- return count > 0
- }
- return count == this.count
- }
|