diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-14 13:39:28 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@datawire.io> | 2022-08-14 17:06:28 -0600 |
commit | 076ca46bad3e18ea7f4c3b3320ab410c3ebea747 (patch) | |
tree | c60c3c056d7cbf07fb086428b984e9a7122d724a | |
parent | 7ce002e865971eb5425230a8a1dec7d936efa1d0 (diff) |
decode: Switch from ReEncoder to Parser
-rw-r--r-- | decode.go | 41 |
1 files changed, 20 insertions, 21 deletions
@@ -561,33 +561,32 @@ func (dec *Decoder) decodeWS() { } func (dec *Decoder) scan(out io.Writer) { - scanner := &ReEncoder{ - Out: out, - Compact: true, - } - if _, err := scanner.WriteRune(dec.readRune()); err != nil { - dec.panicSyntax(err) - } - scanner.bailAfterCurrent = true - var err error - var eof bool - for err == nil { + var scanner Parser + for { c, ok := dec.readRuneOrEOF() + + var t RuneType + var err error if ok { - _, err = scanner.WriteRune(c) + t, err = scanner.HandleRune(c) } else { - eof = true - err = scanner.Flush() - break + t, err = scanner.HandleEOF() } - } - if err != nil { - if err == errBailedAfterCurrent { - if !eof { + + switch t { + case RuneTypeError: + dec.panicSyntax(err) + case RuneTypeEOF: + if ok { dec.unreadRune() } - } else { - dec.panicSyntax(err) + return + case RuneTypeSpace: + // ignore + default: + if _, err := writeRune(out, c); err != nil { + dec.panicIO(err) + } } } } |