forked from x-motemen/gore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_name.go
56 lines (51 loc) · 827 Bytes
/
command_name.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
51
52
53
54
55
56
package gore
import "strings"
type commandName string
func (s commandName) String() string {
var b strings.Builder
for _, c := range s {
if c != '[' && c != ']' {
b.WriteRune(c)
}
}
return b.String()
}
func (s commandName) matches(t string) bool {
var grouping bool
for i, j := 0, 0; j <= len(t); i, j = i+1, j+1 {
if i >= len(s) {
return j == len(t)
}
if s[i] == '[' {
grouping = true
i++
}
if j == len(t) {
break
}
if s[i] == ']' {
return false
}
if s[i] != t[j] {
return false
}
}
return grouping
}
func (s commandName) matchesPrefix(t string) bool {
for i, j := 0, 0; j < len(t); i, j = i+1, j+1 {
if i >= len(s) {
return false
}
if s[i] == '[' {
i++
}
if s[i] == ']' {
return false
}
if s[i] != t[j] {
return false
}
}
return true
}