-
-
Notifications
You must be signed in to change notification settings - Fork 247
/
state_string.go
37 lines (30 loc) · 1016 Bytes
/
state_string.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
package processor
import "fmt"
type StateString struct {
End []byte
SkipEsc bool
}
func (state *StateString) String() string {
return fmt.Sprintf("string[end=%s,skipesc=%v]", state.End, state.SkipEsc)
}
func (state *StateString) Process(job *FileJob, lang *LanguageFeature, index int, lineType LineType) (int, LineType, State) {
var i int
for i = index; i < job.EndPoint; i++ {
// If we hit a newline, return because we want to count the stats but keep
// the current state so we end up back in this loop when the outer
// one calls again
if job.Content[i] == '\n' {
return i, LINE_CODE, state
}
// If we are in a literal string we want to ignore the \ check OR we aren't checking for special ones
if state.SkipEsc || job.Content[i-1] != '\\' {
if checkForMatchSingle(job.Content[i], i, job.EndPoint, state.End, job) {
return i, LINE_CODE, &StateCode{}
}
}
}
return i, LINE_CODE, state
}
func (state *StateString) Reset() (LineType, State) {
return LINE_CODE, state
}