2015-12-24 17:54:54 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-08 20:14:31 +03:00
|
|
|
"strings"
|
2016-01-14 18:29:13 +03:00
|
|
|
"unicode/utf8"
|
2015-12-24 17:54:54 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// raw represents raw string to match
|
|
|
|
type Raw struct {
|
2016-01-14 18:29:13 +03:00
|
|
|
Str string
|
|
|
|
Length int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRaw(s string) Raw {
|
|
|
|
return Raw{
|
|
|
|
Str: s,
|
|
|
|
Length: utf8.RuneCountInString(s),
|
|
|
|
}
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self Raw) Match(s string) bool {
|
|
|
|
return self.Str == s
|
|
|
|
}
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
func (self Raw) Len() int {
|
2016-01-14 18:29:13 +03:00
|
|
|
return self.Length
|
2016-01-09 02:34:41 +03:00
|
|
|
}
|
|
|
|
|
2015-12-24 17:54:54 +03:00
|
|
|
func (self Raw) Kind() Kind {
|
|
|
|
return KindRaw
|
|
|
|
}
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
func (self Raw) Index(s string) (index int, segments []int) {
|
2016-01-08 20:14:31 +03:00
|
|
|
index = strings.Index(s, self.Str)
|
2015-12-24 17:54:54 +03:00
|
|
|
if index == -1 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:29:13 +03:00
|
|
|
segments = []int{self.Length}
|
2015-12-24 17:54:54 +03:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self Raw) String() string {
|
2016-01-11 10:17:19 +03:00
|
|
|
return fmt.Sprintf("<raw:%s>", self.Str)
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|