diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-18 17:25:21 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-18 21:30:12 -0700 |
commit | 595249c55c24828c04ab682dd3b35883b74aa790 (patch) | |
tree | 592723b5b661626f917a39039557809a25ae82a3 | |
parent | 0c112bc16d6970db1bee35710f6c8b0622510663 (diff) |
decode_scan: PopReadBarrier, Reset: De-couple the .repeat and EOF cases
This duplicates code, but it's confusing thinking about them together.
-rw-r--r-- | decode_scan.go | 35 |
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 } } |