summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decode_scan.go35
1 files changed, 30 insertions, 5 deletions
diff --git a/decode_scan.go b/decode_scan.go
index b0fc7c3..507bc42 100644
--- a/decode_scan.go
+++ b/decode_scan.go
@@ -111,7 +111,20 @@ func (sc *runeTypeScanner) PushReadBarrier() {
func (sc *runeTypeScanner) PopReadBarrier() {
sc.parser.PopBarrier()
- if sc.repeat || (sc.rType == jsonparse.RuneTypeEOF && sc.rSize > 0) {
+ switch {
+ case sc.repeat:
+ // re-figure the rType and rErr
+ var err error
+ sc.rType, err = sc.parser.HandleRune(sc.rRune)
+ if err != nil {
+ sc.rErr = &DecodeSyntaxError{
+ Offset: sc.offset - int64(sc.rSize),
+ Err: err,
+ }
+ } else {
+ sc.rErr = nil
+ }
+ case sc.rType == jsonparse.RuneTypeEOF && sc.rSize > 0:
// re-figure the rType and rErr
var err error
sc.rType, err = sc.parser.HandleRune(sc.rRune)
@@ -125,7 +138,7 @@ func (sc *runeTypeScanner) PopReadBarrier() {
}
// tell it to use that rType and rErr
_ = sc.UnreadRune() // we set it up to always succeed
- } else if sc.rType == jsonparse.RuneTypeEOF {
+ case sc.rType == jsonparse.RuneTypeEOF:
// re-figure the rType and rErr
var err error
sc.rType, err = sc.parser.HandleEOF()
@@ -142,8 +155,20 @@ func (sc *runeTypeScanner) PopReadBarrier() {
func (sc *runeTypeScanner) Reset() {
sc.parser.Reset()
- if sc.repeat || (sc.rType == jsonparse.RuneTypeEOF && sc.rSize > 0) {
- sc.repeat = false
+ switch {
+ case sc.repeat:
+ // re-figure the rType and rErr
+ var err error
+ sc.rType, err = sc.parser.HandleRune(sc.rRune)
+ if err != nil {
+ sc.rErr = &DecodeSyntaxError{
+ Offset: sc.offset - int64(sc.rSize),
+ Err: err,
+ }
+ } else {
+ sc.rErr = nil
+ }
+ case sc.rType == jsonparse.RuneTypeEOF && sc.rSize > 0:
// re-figure the rType and rErr
var err error
sc.rType, err = sc.parser.HandleRune(sc.rRune)
@@ -157,7 +182,7 @@ func (sc *runeTypeScanner) Reset() {
}
// tell it to use that rType and rErr
_ = sc.UnreadRune() // we set it up to always succeed
- } else {
+ default:
sc.initialized = false
}
}