diff options
-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) + } } } } |