diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-10 20:48:21 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-10 21:52:22 -0700 |
commit | dadafd9cfabbea5555c404b339bbf44252ee7e6b (patch) | |
tree | d228bb78a08586cab74e0a3df292fa8e9c266f90 | |
parent | d525a9ad920c6678f1e193d121be677936289667 (diff) |
decode: decodeAny: Use rune types rather that char literals
-rw-r--r-- | decode.go | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -891,13 +891,12 @@ func (dec *Decoder) scanNumber(gTyp reflect.Type, out fastio.RuneWriter) *Decode } func (dec *Decoder) decodeAny() (any, *DecodeError) { - c, _, err := dec.readRune() + t, err := dec.peekRuneType() if err != nil { return nil, err } - dec.unreadRune() - switch c { - case '{': + switch t { + case jsonparse.RuneTypeObjectBeg: ret := make(map[string]any) typ := reflect.TypeOf(ret) var nameBuf strings.Builder @@ -922,7 +921,7 @@ func (dec *Decoder) decodeAny() (any, *DecodeError) { return nil, err } return ret, nil - case '[': + case jsonparse.RuneTypeArrayBeg: ret := []any{} typ := reflect.TypeOf(ret) if err := dec.decodeArray(typ, func() *DecodeError { @@ -940,13 +939,13 @@ func (dec *Decoder) decodeAny() (any, *DecodeError) { return nil, err } return ret, nil - case '"': + case jsonparse.RuneTypeStringBeg: var buf strings.Builder if err := dec.decodeString(nil, &buf); err != nil { return nil, err } return buf.String(), nil - case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': + case jsonparse.RuneTypeNumberIntNeg, jsonparse.RuneTypeNumberIntZero, jsonparse.RuneTypeNumberIntDig: var buf strings.Builder if err := dec.scan(&buf); err != nil { return nil, err @@ -960,9 +959,9 @@ func (dec *Decoder) decodeAny() (any, *DecodeError) { return nil, dec.newTypeError("number "+buf.String(), float64Type, err) } return f64, nil - case 't', 'f': + case jsonparse.RuneTypeTrueT, jsonparse.RuneTypeFalseF: return dec.decodeBool(nil) - case 'n': + case jsonparse.RuneTypeNullN: return nil, dec.decodeNull() default: panic("should not happen") |