From 595249c55c24828c04ab682dd3b35883b74aa790 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 18 Feb 2023 17:25:21 -0700 Subject: decode_scan: PopReadBarrier, Reset: De-couple the .repeat and EOF cases This duplicates code, but it's confusing thinking about them together. --- decode_scan.go | 35 ++++++++++++++++++++++++++++++----- 1 file 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 } } -- cgit v1.2.3-2-g168b