forked from BobuSumisu/go-ahocorasick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch.go
41 lines (31 loc) · 949 Bytes
/
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
package ahocorasick
import (
"bytes"
"fmt"
)
// Represents a matched pattern.
type Match struct {
pos int64
match []byte
}
func newMatch(pos int64, match []byte) *Match {
return &Match{pos, match}
}
func newMatchString(pos int64, match string) *Match {
return &Match{pos, []byte(match)}
}
func (m *Match) String() string {
return fmt.Sprintf("{%v %q}", m.pos, m.match)
}
// Get the position (offset) of the matched pattern.
func (m *Match) Pos() int64 { return m.pos }
// Get the end position of the matched pattern.
func (m *Match) End() int64 { return m.pos + int64(len(m.match)) }
// Get the matched byte pattern.
func (m *Match) Match() []byte { return m.match }
// Just to make working with strings a little more comfortable.
func (m *Match) MatchString() string { return string(m.match) }
// Check if two matches are equal.
func MatchEqual(m1, m2 *Match) bool {
return bytes.Equal(m1.match, m2.match) && m1.pos == m2.pos
}