Browse Source

JSON float parsing bug behoben

Kolja Strohm 4 years ago
parent
commit
b6c9a99909
1 changed files with 5 additions and 11 deletions
  1. 5 11
      JSON.cpp

+ 5 - 11
JSON.cpp

@@ -417,19 +417,13 @@ JSONValue *Parser::getValue( const char *str )
         return new JSONObject( string );
     if( Text( (int)string ).istGleich( string.getText() ) )
         return new JSONNumber( string );
-    if( string.anzahlVon( '.' ) )
+    if( string.anzahlVon( '.' ) == 1 )
     {
-        Text *first = string.getTeilText( 0, string.positionVon( '.' ) );
-        Text *last = string.getTeilText( string.positionVon( '.' ) + 1 );
-        if( Text( (int)* first ).istGleich( first->getText() ) &&
-            Text( (int)* last ).istGleich( last->getText() ) )
-        {
-            first->release();
-            last->release();
+        bool isNumber = 1;
+        for( char *c = string.getText(); c; c++ )
+            isNumber &= ( *c >= '0' && *c <= '9' ) || *c == '.';
+        if( isNumber )
             return new JSONNumber( string );
-        }
-        first->release();
-        last->release();
     }
     return new JSONValue();
 }