std.json parsing real numbers.

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Aug 8 09:34:44 PDT 2013


On Thu, Aug 08, 2013 at 05:20:16PM +0200, Borislav Kosharov 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? If you think it should be
> 2.24 you are wrong.

If you think it should be 12.4, you're wrong too. This is illegal syntax
according to the JSON spec and RFC 4627 (see sections 2 and 2.4:
whitespace is not allowed inside a number literal). It should throw an
exception, not return any value.


T

-- 
IBM = I Blame Microsoft


More information about the Digitalmars-d mailing list