Return 1.9.1 functionality where values too large to fit in
double are converted to positive or negative infinity.
Commit 645cd04 changed functionality so that large floats cause
parse error, while version 1.9.1 accepted them as infinite.
This is problematic because writer outputs infinity values
as `1e+9999`, which could no longer be parsed back.
Fixed also legacy Reader even though it did not parse large values
even before breaking change, due to problematic output/parse asymmetry.
`>>` operator sets value to numeric_limits::max/lowest value if
representation is too large to fit to double. [1][2] In macos
value appears to be parsed to infinity.
> | value in *val* | description |
> |--------------------------|-------------|
> | numeric_limits::max() | The sequence represents a value too large for the type of val |
> | numeric_limits::lowest() | The sequence represents a value too large negative for the type of val |
[1] https://www.cplusplus.com/reference/istream/istream/operator%3E%3E/
[2] https://www.cplusplus.com/reference/locale/num_get/get/
Signed-off-by: Tero Kinnunen <tero.kinnunen@vaisala.com>
Co-authored-by: Tero Kinnunen <tero.kinnunen@vaisala.com>
* Fix a precision bug of valueToString, prevent to give an error result on input of wanted precision 0 and a double value which end of zero before decimal point ,such as 1230.01,12300.1;
Add test cases for double valueToString with precision 0;
* Delete a test case with platform differences in the previous commit
* Fix clang-format.
* Fix clang-format!
Co-authored-by: lilei <dlilei@126.com>
* BUILD_TYPE corresponds to Release/Debug
but LIB_TYPE corresponds to shared/static.
* Add support to build shared, static and object lib at the same time.
* avoid isprint
`std::isprint` is locale-specific and the JSON-spec is not.
In particular, isprint('\t') is true in Windows CP1252.
Has bitten others, e.g. https://github.com/laurikari/tre/issues/64Fixes#1187
* semicolon (rookie mistake!)
* Windows tab escape testing with custom locale (#1190)
Co-authored-by: Nikolay Baklicharov <thestorm.nik@gmail.com>
* avoid isprint
`std::isprint` is locale-specific and the JSON-spec is not.
In particular, isprint('\t') is true in Windows CP1252.
Has bitten others, e.g. https://github.com/laurikari/tre/issues/64Fixes#1187
* semicolon (rookie mistake!)
This patch fixes a fuzzing bug by resolving a bad fallthrough in the
setComment logic.
The result is that we get a proper error instead of an assert, making
the library friendlier to use and less likely to cause issue for
consumers.
See related Chromium project bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=989851
Issue: 1182
* [clang-tidy] change functions to static
Found with readability-convert-member-functions-to-static
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* optimize JsonWriter::validate #1171
* do the same for json_reader
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* use std::any_of
Also simplified two loops.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Billy Donahue <billy.donahue@gmail.com>
Commit aebc7fa added version checks for CMake compatibility. In reality,
only the add_compile_definitions need the check - add_compile_options
itself has been supported since 3.0. Tested and confirmed built
successfully with CMake 3.8.0.
The more general CMake way to handle library suffixing is to set
CMAKE_<CONFIG>_POSTFIX, so setting the Debug output suffix name should
be more correctly done by the caller or CMake configurer by setting
the desired value in CMAKE_DEBUG_POSTFIX.
* [clang-tidy] remove redundant string initialization
Found with readability-redundant-string-init
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* [clang-tidy] switch to raw strings
Easier to read.
Found with modernize-raw-string-literal
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* [clang-tidy] fix performance issues
Found with performance*
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* fix extra comma warnings
Found with clang's -Wextra-semi-stmt
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* remove JSONCPP_OP_EXPLICIT
This codebase in C++11. No need for compatibility with C++98.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* remove JSONCPP_NOEXCEPT
This codebase is C++11 now. No need for this macro.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* [clang-tidy] Do not use else after return
Found with readability-else-after-return
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* [clang-tidy] Convert several loops to be range based
Found with modernize-loop-convert
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* [clang-tidy] Replace deprecated C headers
Found with modernize-deprecated-headers
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* [clang-tidy] Use auto where applicable
Found with modernize-use-auto
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* .clang-tidy: Add these checks
This bug is only affects platforms where `char` is unsigned.
When char is a signed type, values >= 0x80 are also considered < 0,
and hence require escaping due to the < ' ' condition.
When char is an unsigned type, values >= 0x80 match none of the
conditions and are considered safe to emit without escaping.
This shows up as a test failure:
* Detail of EscapeSequenceTest/writeEscapeSequence test failure:
/build/source/src/test_lib_json/main.cpp(3370): expected == result
Expected: '["\"","\\","\b","\f","\n","\r","\t","\u0278","\ud852\udf62"]
'
Actual : '["\"","\\","\b","\f","\n","\r","\t","ɸ","𤭢"]
'
CPPTL support is no longer relevant to JsonCpp, and can be removed from
the library. This patch removes all mentions of CPPTL, by removing all
definitions and code sections conditionally compiled only when JsonCpp
is used with CPPTL. Include guards are also renamed to not refer to
CPPTL where appropriate.