Introduce jsontext.RawToken API for better number parsing #158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Decoder now returns RawToken instead of Token. RawToken exposes a new set of methods:
They reuses the same logic of arshalers, intended to offers Decoder user a more efficient and convenient way to parse numbers.
New jsontext.Raw and Token.Raw func are added to convert between RawToken and Token.
The original Float, Int, Uint methods now only support the case where the Token is created by the correspond constructor. e.g., Int(1).Uint() will panic. This should ensure we will never get inaccurate values.
Other behavior changes:
nonfinite
is still supported in json package.This is inspired by the idea in golang/go#63397 (reply in thread) . I expand the idea of @neild , and add a new RawToken type. Now
RawToken
is used in Decoding, it only haveParseFloat
intended for decodeToken
is still used in Encoding,Token.Float
now become a simple accessor to retrieve the value set byjsontext.Float
.With this design, we give up support for any inaccurate cases. Then we can answer the edge cases that @dsnet raised in the discussion naturally:
strconv.ParseInt
strconv.ParseInt