forked from BobuSumisu/aho-corasick
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch.go
More file actions
42 lines (32 loc) · 1.1 KB
/
match.go
File metadata and controls
42 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ahocorasick
import (
"bytes"
"fmt"
)
// Match represents a matched pattern in the input.
type Match struct {
pos uint32
pattern uint32
match []byte
}
func newMatch(pos, pattern uint32, match []byte) *Match {
return &Match{pos, pattern, match}
}
func newMatchString(pos, pattern uint32, match string) *Match {
return &Match{pos: pos, pattern: pattern, match: []byte(match)}
}
func (m *Match) String() string {
return fmt.Sprintf("{%d %d %q}", m.pos, m.pattern, m.match)
}
// Pos returns the byte position of the match.
func (m *Match) Pos() uint32 { return m.pos }
// Pattern returns the pattern id of the match.
func (m *Match) Pattern() uint32 { return m.pattern }
// Match returns the pattern matched.
func (m *Match) Match() []byte { return m.match }
// MatchString returns the pattern matched as a string.
func (m *Match) MatchString() string { return string(m.match) }
// MatchEqual check whether two matches are equal (i.e. at same position, pattern and same pattern).
func MatchEqual(a, b *Match) bool {
return a.pos == b.pos && a.pattern == b.pattern && bytes.Equal(a.match, b.match)
}