mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
717 B
46 lines
717 B
5 years ago
|
package match
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"unicode/utf8"
|
||
|
)
|
||
|
|
||
|
// raw represents raw string to match
|
||
|
type Text struct {
|
||
|
Str string
|
||
|
RunesLength int
|
||
|
BytesLength int
|
||
|
Segments []int
|
||
|
}
|
||
|
|
||
|
func NewText(s string) Text {
|
||
|
return Text{
|
||
|
Str: s,
|
||
|
RunesLength: utf8.RuneCountInString(s),
|
||
|
BytesLength: len(s),
|
||
|
Segments: []int{len(s)},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (self Text) Match(s string) bool {
|
||
|
return self.Str == s
|
||
|
}
|
||
|
|
||
|
func (self Text) Len() int {
|
||
|
return self.RunesLength
|
||
|
}
|
||
|
|
||
|
func (self Text) Index(s string) (int, []int) {
|
||
|
index := strings.Index(s, self.Str)
|
||
|
if index == -1 {
|
||
|
return -1, nil
|
||
|
}
|
||
|
|
||
|
return index, self.Segments
|
||
|
}
|
||
|
|
||
|
func (self Text) String() string {
|
||
|
return fmt.Sprintf("<text:`%v`>", self.Str)
|
||
|
}
|