-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruleref_special.go
More file actions
48 lines (37 loc) · 871 Bytes
/
ruleref_special.go
File metadata and controls
48 lines (37 loc) · 871 Bytes
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
package srgs
import (
"fmt"
"strings"
)
type Garbage struct {
match string
scanMatch bool
currentInd int
}
func (g *Garbage) Match(str string, mode MatchMode) {
g.currentInd = -1
g.match = str
}
func (g *Garbage) Next() (string, error) {
if g.currentInd == len(g.match) {
return "", NoMatch
}
if g.currentInd != -1 {
ind := strings.Index(g.match[g.currentInd:], " ")
if ind == -1 {
ind = len(g.match) - 1 - g.currentInd
}
g.currentInd += ind
}
g.currentInd++
return g.match[g.currentInd:], nil
}
func (g *Garbage) Copy(r RuleRefs) Expansion {
return &Garbage{match: g.match, currentInd: g.currentInd, scanMatch: g.scanMatch}
}
func (g *Garbage) Scan(processor Processor) {
processor.AppendTag(fmt.Sprintf(`
scopes[scopes.length-1]['GARBAGE'] = "%s";
`, g.match[:g.currentInd]))
processor.AppendString(g.match[:g.currentInd])
}