summaryrefslogtreecommitdiff
path: root/vendor/github.com/tdewolff/parse/v2/input.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tdewolff/parse/v2/input.go')
-rw-r--r--vendor/github.com/tdewolff/parse/v2/input.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/vendor/github.com/tdewolff/parse/v2/input.go b/vendor/github.com/tdewolff/parse/v2/input.go
index 5b6d8f547..924f14f0c 100644
--- a/vendor/github.com/tdewolff/parse/v2/input.go
+++ b/vendor/github.com/tdewolff/parse/v2/input.go
@@ -92,7 +92,7 @@ func (z *Input) Err() error {
func (z *Input) PeekErr(pos int) error {
if z.err != nil {
return z.err
- } else if z.pos+pos >= len(z.buf)-1 {
+ } else if len(z.buf)-1 <= z.pos+pos {
return io.EOF
}
return nil
@@ -109,11 +109,11 @@ func (z *Input) Peek(pos int) byte {
func (z *Input) PeekRune(pos int) (rune, int) {
// from unicode/utf8
c := z.Peek(pos)
- if c < 0xC0 || z.Peek(pos+1) == 0 {
+ if c < 0xC0 || len(z.buf)-1-z.pos < 2 {
return rune(c), 1
- } else if c < 0xE0 || z.Peek(pos+2) == 0 {
+ } else if c < 0xE0 || len(z.buf)-1-z.pos < 3 {
return rune(c&0x1F)<<6 | rune(z.Peek(pos+1)&0x3F), 2
- } else if c < 0xF0 || z.Peek(pos+3) == 0 {
+ } else if c < 0xF0 || len(z.buf)-1-z.pos < 4 {
return rune(c&0x0F)<<12 | rune(z.Peek(pos+1)&0x3F)<<6 | rune(z.Peek(pos+2)&0x3F), 3
}
return rune(c&0x07)<<18 | rune(z.Peek(pos+1)&0x3F)<<12 | rune(z.Peek(pos+2)&0x3F)<<6 | rune(z.Peek(pos+3)&0x3F), 4
@@ -124,6 +124,20 @@ func (z *Input) Move(n int) {
z.pos += n
}
+// MoveRune advances the position by the length of the current rune.
+func (z *Input) MoveRune() {
+ c := z.Peek(0)
+ if c < 0xC0 || len(z.buf)-1-z.pos < 2 {
+ z.pos++
+ } else if c < 0xE0 || len(z.buf)-1-z.pos < 3 {
+ z.pos += 2
+ } else if c < 0xF0 || len(z.buf)-1-z.pos < 4 {
+ z.pos += 3
+ } else {
+ z.pos += 4
+ }
+}
+
// Pos returns a mark to which can be rewinded.
func (z *Input) Pos() int {
return z.pos - z.start