summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decode.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/decode.go b/decode.go
index 03d5b7a..32912ec 100644
--- a/decode.go
+++ b/decode.go
@@ -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)
+ }
}
}
}