diff --git a/composer.json b/composer.json index d95c073..11ab696 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "autoload": { "psr-0": { - "JsonStreamingParser": "src/" + "JsonStreamingParser\\": "src/" } } } diff --git a/src/JsonStreamingParser/Parser.php b/src/JsonStreamingParser/Parser.php index 86986e4..af29698 100644 --- a/src/JsonStreamingParser/Parser.php +++ b/src/JsonStreamingParser/Parser.php @@ -531,11 +531,16 @@ private function startNumber($c) private function endNumber() { $num = $this->buffer; - if (preg_match('/\./', $num)) { - $num = (float) ($num); - } else { - $num = (int) ($num); + + if (ctype_digit($num) && ((float)$num === (float)((int)$num))) { + // natural number PHP_INT_MIN < $num < PHP_INT_MAX + $num = (int)$num; } + else { + // real number or natural number outside PHP_INT_MIN ... PHP_INT_MAX + $num = (float)$num; + } + $this->listener->value($num); $this->buffer = '';