Browse Source

Merge pull request #8405 from afishbeck/jsonScientificNotation

HPCC-14928 Add support for parsing json scientific notation values

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 9 years ago
parent
commit
c3bf484f66
1 changed files with 15 additions and 2 deletions
  1. 15 2
      system/jlib/jptree.cpp

+ 15 - 2
system/jlib/jptree.cpp

@@ -6407,11 +6407,24 @@ protected:
             if (!isdigit(nextChar))
                 error("Bad value");
             type = elementTypeInteger;
-            while (isdigit(nextChar) || '.'==nextChar)
+            bool exponent = false;
+            while (isdigit(nextChar) || '.'==nextChar || 'e'==nextChar || 'E'==nextChar)
             {
+                if ('e'==nextChar || 'E'==nextChar)
+                {
+                    if (exponent)
+                        error("Bad value");
+                    exponent=true;
+                    value.append(nextChar);
+                    readNext();
+                    if ('-'==nextChar)
+                        type=elementTypeReal;
+                    else if (!isdigit(nextChar) && '+'!=nextChar)
+                        error("Bad value");
+                }
                 if ('.'==nextChar)
                 {
-                    if (type==elementTypeReal) //already found decimal
+                    if (exponent || type==elementTypeReal) //already found decimal
                         error("Bad value");
                     type = elementTypeReal;
                 }