diff options
Diffstat (limited to 'lib/lowmemjson/decode.go')
-rw-r--r-- | lib/lowmemjson/decode.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/lowmemjson/decode.go b/lib/lowmemjson/decode.go index 33b4222..6726ca8 100644 --- a/lib/lowmemjson/decode.go +++ b/lib/lowmemjson/decode.go @@ -60,6 +60,14 @@ func peekRune(r io.RuneScanner) rune { return c } +func peekRuneOrEOF(r io.RuneScanner) (rune, bool) { + c, ok := readRuneOrEOF(r) + if ok { + unreadRune(r) + } + return c, ok +} + func expectRune(r io.RuneReader, exp rune) { act := readRune(r) if act != exp { @@ -279,7 +287,11 @@ func decode(r io.RuneScanner, ptrVal reflect.Value) { func decodeWS(r io.RuneScanner) { for { - switch readRune(r) { + c, ok := readRuneOrEOF(r) + if !ok { + return + } + switch c { // NB: The JSON definition of whitespace is more // narrow than unicode.IsSpace case 0x0020, 0x000A, 0x000D, 0x0009: |