* Introduce CharReaderBuilder::ecma404Mode
* Bump micro version
---------
Co-authored-by: Jordan Bayles <jophba@chromium.org>
Co-authored-by: Billy Donahue <BillyDonahue@users.noreply.github.com>
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
* Opportunistically take advantage of C++20 move-out-of stringstream
* Opportunistically take advantage of C++20 move-in/out-of stringstream
---------
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
Currently removeIndex copies the removed value into removed and then
destructs the original, which can cause significant performance overhead.
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
* CharReader: Add Structured Error
Add getStructuredError to CharReader
* run clang format
---------
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
Co-authored-by: Jordan Bayles <jophba@chromium.org>
* add a valueToQuotedString overload to take a string length to support things like a string_view more directly.
* Apply suggestions from code review
Co-authored-by: Billy Donahue <BillyDonahue@users.noreply.github.com>
---------
Co-authored-by: Billy Donahue <BillyDonahue@users.noreply.github.com>
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
The existing asserts seem to not be what was intended; they appear to have been mistranslated in pull/877.
The first assert for `comment.empty()` was previously a check that a provided `const char*` parameter was not null. The function this replaced accepted empty strings, and the if() statement at the start of this function handles them.
The second assert for `comment[0] == '\0'` was written when `comment` was a `const char*`, and was testing for empty c-string input. This PR replaces it with `comment.empty()` to match the original intent.
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
getLocationLIneAndColumn would read past the end of the provided buffer if generating an error message at the end of the stream, if the final character was `\r`.
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
* Fix a parser bug where tokens are misidentified as commas.
In the old and new readers, when parsing an object, a comment
followed by any non-`}` token is treated as a comma.
The new unit test required changing the runjsontests.py
flag regime so that failure tests could be run with default settings.
* Honor allowComments==false mode.
Much of the comment handling in the parsers is bespoke, and does not
honor this flag. By unfiying it under a common API, the parser is
simplified and strict mode is now more correctly strict.
Note that allowComments mode does not allow for comments in
arbitrary locations; they are allowed only in certain positions.
Rectifying this is a bigger effort, since collectComments mode requires
storing the comments somewhere, and it's not immediately clear
where in the DOM all such comments should live.
---------
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
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>