Podger2016 / rapidjson

Automatically exported from code.google.com/p/rapidjson
0 stars 0 forks source link

Parsing float numbers with dot but without fraction part. #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello. I use rapidjson on server part to parse strings which are created on 
client side with Flash (ActionScript3) and sometimes (when value become equal 
to integer, I suppose) float numbers are written with dot, but without fraction 
part, e.i.: {"float_value":123.}
Adobe's JSON parser parses it well, but rapidjson refuses to parse it, so I 
made small modifications to continue parsing of such values.
Here is the patch, hope, it is possible to apply it on repository:

===================================================================
--- rapidjson/include/rapidjson/reader.h        (revision 64)
+++ rapidjson/include/rapidjson/reader.h        (working copy)
@@ -542,20 +542,30 @@
                                useDouble = true;
                        }
                        s.Take();
-
+
+                       bool done = false;
+
                        if (s.Peek() >= '0' && s.Peek() <= '9') {
                                d = d * 10 + (s.Take() - '0');
                                --expFrac;
                        }
                        else
-                               RAPIDJSON_PARSE_ERROR("At least one digit in 
fraction part", is.Tell());
-
-                       while (s.Peek() >= '0' && s.Peek() <= '9') {
-                               if (expFrac > -16) {
-                                       d = d * 10 + (s.Peek() - '0');
-                                       --expFrac;
+                       {
+                               //some JSON library which I used to form the 
database (maybe even rapidjson) written fractional numbers with a dot at end, 
so just skip such errors):
+                               //RAPIDJSON_PARSE_ERROR("At least one digit in 
fraction part", is.Tell());
+                               done = true;
+                       }
+
+                       if ( !done )
+                       {
+                               while (s.Peek() >= '0' && s.Peek() <= '9')
+                               {
+                                       if (expFrac > -16) {
+                                               d = d * 10 + (s.Peek() - '0');
+                                               --expFrac;
+                                       }
+                                       s.Take();
                                }
-                               s.Take();
                        }
                }

Thank you!

Original issue reported on code.google.com by Slav...@gmail.com on 22 Aug 2012 at 5:05

GoogleCodeExporter commented 8 years ago
http://www.ietf.org/rfc/rfc4627.txt

2.4.  Numbers
... "A fraction part is a decimal point followed by one or more digits."

I think it will be convenient to add support for relaxed syntax rules. But the 
current implementation is not a defect.

Original comment by milo...@gmail.com on 18 Oct 2012 at 8:19

GoogleCodeExporter commented 8 years ago
I wrongfully subbmitted it as "bug" - didn't changed anything and google used 
"bug" type by default, sorry.
It is surely the "enhancement".
Thanks for accepting!

Original comment by Slav...@gmail.com on 18 Oct 2012 at 9:59

GoogleCodeExporter commented 8 years ago
This issue has been merged to https://github.com/miloyip/rapidjson/issues/36 
for further discussion.

Original comment by milo...@gmail.com on 13 Jul 2014 at 4:37