fastfloat / fast_float

Fast and exact implementation of the C++ from_chars functions for number types: 4x to 10x faster than strtod, part of GCC 12, Chromium, Redis and WebKit/Safari
Apache License 2.0
1.54k stars 132 forks source link

Add support for parsing numbers according to JSON format #220

Closed mayawarrier closed 1 year ago

mayawarrier commented 1 year ago

Details on the format are available here (RFC 8259): https://datatracker.ietf.org/doc/html/rfc8259#section-6 This is compatible with previous JSON RFCs as well as the number format hasn't changed.

lemire commented 1 year ago

Looks like a good idea. I will review and I expect to merge.

lemire commented 1 year ago

@mayawarrier I think that the JSON format does not allow a leading +... only in the exponent, so 1e+1 is ok, but +1e1 is not.

mayawarrier commented 1 year ago

@mayawarrier I think that the JSON format does not allow a leading +... only in the exponent, so 1e+1 is ok, but +1e1 is not.

Got it, I'll just ignore the FASTFLOAT_ALLOWS_LEADING_PLUS macro when the runtime format is json.

mayawarrier commented 1 year ago

I disallowed leading pluses as requested. I also added an option to allow inf/nan in JSON mode. This is a common option in JSON parsers despite not being part of the standard.

lemire commented 1 year ago

I am sure that this could be perfected, but it looks solid to me, merging.