-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextract_json.go
41 lines (32 loc) · 932 Bytes
/
extract_json.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
package unneko
type bracketCounterCompleteCond struct {
openBracket byte
closeBracket byte
previousDelta int
previousPos int
}
func newBracketCounterCompleteCond(openBracket byte, closeBracket byte) *bracketCounterCompleteCond {
return &bracketCounterCompleteCond{
openBracket: openBracket,
closeBracket: closeBracket,
}
}
func (c *bracketCounterCompleteCond) Complete(neko *nekoData, uncompressed []byte) bool {
currentDelta := c.getBracketDelta(uncompressed[c.previousPos:])
delta := c.previousDelta + currentDelta
c.previousPos = len(uncompressed)
c.previousDelta = delta
return neko.fullyRead() || (len(uncompressed) > 0 && delta == 0)
}
func (c *bracketCounterCompleteCond) getBracketDelta(data []byte) int {
bracketDelta := 0
for i := 0; i < len(data); i++ {
if data[i] == c.openBracket {
bracketDelta++
}
if data[i] == c.closeBracket {
bracketDelta--
}
}
return bracketDelta
}