@@ -26,10 +26,11 @@ type RangeScanner struct {
26
26
b []byte
27
27
cb bufio.SplitFunc
28
28
29
- pos Pos // position of next byte to process in b
30
- cur Range // latest range
31
- tok []byte // slice of b that is covered by cur
32
- err error // error from last scan, if any
29
+ start Pos // position of first byte
30
+ pos Pos // position of next byte to process
31
+ cur Range // latest range
32
+ tok []byte // slice of b that is covered by cur
33
+ err error // error from last scan, if any
33
34
}
34
35
35
36
// NewRangeScanner creates a new RangeScanner for the given buffer, producing
@@ -55,19 +56,22 @@ func NewRangeScannerFragment(b []byte, filename string, start Pos, cb bufio.Spli
55
56
b : b ,
56
57
cb : cb ,
57
58
pos : start ,
59
+ start : start ,
58
60
}
59
61
}
60
62
61
63
func (sc * RangeScanner ) Scan () bool {
62
- if sc .pos .Byte >= len (sc .b ) || sc .err != nil {
64
+ currentByte := sc .pos .Byte - sc .start .Byte
65
+
66
+ if currentByte >= len (sc .b ) || sc .err != nil {
63
67
// All done
64
68
return false
65
69
}
66
70
67
71
// Since we're operating on an in-memory buffer, we always pass the whole
68
72
// remainder of the buffer to our SplitFunc and set isEOF to let it know
69
73
// that it has the whole thing.
70
- advance , token , err := sc .cb (sc .b [sc . pos . Byte :], true )
74
+ advance , token , err := sc .cb (sc .b [currentByte :], true )
71
75
72
76
// Since we are setting isEOF to true this should never happen, but
73
77
// if it does we will just abort and assume the SplitFunc is misbehaving.
@@ -95,7 +99,7 @@ func (sc *RangeScanner) Scan() bool {
95
99
// we're being asked to skip over by the SplitFunc.
96
100
// adv is a slice covering any additional bytes we are skipping over, based
97
101
// on what the SplitFunc told us to do with advance.
98
- adv := sc .b [sc . pos . Byte : sc . pos . Byte + advance ]
102
+ adv := sc .b [currentByte : currentByte + advance ]
99
103
100
104
// We now need to scan over our token to count the grapheme clusters
101
105
// so we can correctly advance Column, and count the newlines so we
0 commit comments