std.json parsing real numbers.

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Aug 10 13:26:26 PDT 2013


On Sat, Aug 10, 2013 at 09:18:42PM +0200, Borislav Kosharov wrote:
> On Saturday, 10 August 2013 at 18:28:31 UTC, H. S. Teoh wrote:
> >On Thu, Aug 08, 2013 at 08:46:15PM +0200, Borislav Kosharov wrote:
> >>On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky
> >>wrote:
> >>>On Thu, 08 Aug 2013 17:20:16 +0200
> >>>"Borislav Kosharov" <bosak at gmail.com> wrote:
> >>>
> >>>>On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
> >>>>> On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
> >>>>>> On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid >>>>
> >>wrote:
> >>>>>>>
> >>>>>>> I just check  std.json for parsing real numbers.
> >>>>>>>
> >>>>>>> import std.json;
> >>>>>>> import std.stdio: writeln;
> >>>>>>>
> >>>>>>> int main()
> >>>>>>> {
> >>>>>>> 	auto json = parseJSON("1        .24E          +1");
> >>>>>>> 	writeln(toJSON(&json));
> >>>>>>> 	return 0;
> >>>>>>> }
> >>>>>>>
> >>>>>>> and
> >>>>>>> output:  12.4
> >>>>>>>
> >>>>>>>
> >>>>>>> It's bug or normal ?
> >>>>>>
> >>>>>> Yep, because 1.24E+1 is 12.4E0
> >>>>>
> >>>>> I wrote not a "1.24E+1", a "1     .24E     +1"  with >>>
> >>leading >
> >>>>spaces.
> >>>>
> >>>>Well what should it be if it's not 12.4?
> >>>
> >>>A syntax error.
> >>
> >>I don't think this would cause any problems. It would just throw
> >>syntax error because there is white-space between? It would be just
> >>annoying to get syntax error because of extra white-space.
> >>
> >>Maybe this is one of the situations where we should think "It's not
> >>a bug, it's a feature!"
> >>
> >>Unless there is a situation that would make no sense to work or
> >>something, it should be left like it is now.
> >
> >This makes std.json non-conformant to the JSON spec. What if the
> >extra white-space is an indication of data corruption? We should not
> >blindly accept it just because we can.
> >
> >
> >T
> 
> Sorry, I tough that white-space was allowed in JSON, but I didn't
> red the specification before posting. If that is what the spec says
> then I agree too to stay strict with it.

Whitespace is allowed only surrounding certain structural characters,
which are specified in RFC4627 (http://www.ietf.org/rfc/rfc4627.txt,
section 2) as:

	[ { ] } : ,

I take that to mean that everywhere else, whitespace is significant, so
inserting spaces inside a float literal is an error.


T

-- 
Fact is stranger than fiction.


More information about the Digitalmars-d mailing list