-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmatch.go
50 lines (40 loc) · 1.1 KB
/
match.go
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
43
44
45
46
47
48
49
50
package ahocorasick
import (
"bytes"
"fmt"
)
// Match represents a matched pattern in the input.
type Match struct {
pos int64
pattern int64
match []byte
}
func newMatch(pos, pattern int64, match []byte) *Match {
return &Match{pos, pattern, match}
}
func newMatchString(pos, pattern int64, 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() int64 {
return m.pos
}
// Pattern returns the pattern id of the match.
func (m *Match) Pattern() int64 {
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)
}