summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-14 13:39:28 -0600
committerLuke Shumaker <lukeshu@datawire.io>2022-08-14 17:06:28 -0600
commit076ca46bad3e18ea7f4c3b3320ab410c3ebea747 (patch)
treec60c3c056d7cbf07fb086428b984e9a7122d724a
parent7ce002e865971eb5425230a8a1dec7d936efa1d0 (diff)
decode: Switch from ReEncoder to Parser
-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)
+ }
}
}
}