mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-15 15:16:47 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b4e88e35be | ||
![]() |
a888632781 | ||
![]() |
dca8a24cf8 | ||
![]() |
3f86349128 | ||
![]() |
2b3815c90d | ||
![]() |
bd25fc5ea0 | ||
![]() |
8214f717e7 | ||
![]() |
07e3d1b076 | ||
![]() |
871f0cc43b | ||
![]() |
54fc4e28ed | ||
![]() |
76ff1db84d |
2
AUTHORS
2
AUTHORS
@@ -16,7 +16,7 @@ Baruch Siach <baruch@tkos.co.il>
|
|||||||
Ben Boeckel <mathstuf@gmail.com>
|
Ben Boeckel <mathstuf@gmail.com>
|
||||||
Benjamin Knecht <bknecht@logitech.com>
|
Benjamin Knecht <bknecht@logitech.com>
|
||||||
Bernd Kuhls <bernd.kuhls@t-online.de>
|
Bernd Kuhls <bernd.kuhls@t-online.de>
|
||||||
Billy Donahue <billydonahue@google.com>
|
Billy Donahue <billy.donahue@gmail.com>
|
||||||
Braden McDorman <bmcdorman@gmail.com>
|
Braden McDorman <bmcdorman@gmail.com>
|
||||||
Brandon Myers <bmyers1788@gmail.com>
|
Brandon Myers <bmyers1788@gmail.com>
|
||||||
Brendan Drew <brendan.drew@daqri.com>
|
Brendan Drew <brendan.drew@daqri.com>
|
||||||
|
@@ -62,11 +62,11 @@ project(jsoncpp
|
|||||||
# 2. ./include/json/version.h
|
# 2. ./include/json/version.h
|
||||||
# 3. ./CMakeLists.txt
|
# 3. ./CMakeLists.txt
|
||||||
# IMPORTANT: also update the PROJECT_SOVERSION!!
|
# IMPORTANT: also update the PROJECT_SOVERSION!!
|
||||||
VERSION 1.9.6 # <major>[.<minor>[.<patch>[.<tweak>]]]
|
VERSION 1.9.7 # <major>[.<minor>[.<patch>[.<tweak>]]]
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||||
set(PROJECT_SOVERSION 26)
|
set(PROJECT_SOVERSION 27)
|
||||||
|
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake)
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake)
|
||||||
@@ -93,6 +93,12 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir.")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
include(CheckFunctionExists)
|
||||||
|
check_function_exists(memset_s HAVE_MEMSET_S)
|
||||||
|
if(HAVE_MEMSET_S)
|
||||||
|
add_definitions("-DHAVE_MEMSET_S=1")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(JSONCPP_USE_SECURE_MEMORY)
|
if(JSONCPP_USE_SECURE_MEMORY)
|
||||||
add_definitions("-DJSONCPP_USE_SECURE_MEMORY=1")
|
add_definitions("-DJSONCPP_USE_SECURE_MEMORY=1")
|
||||||
endif()
|
endif()
|
||||||
|
@@ -9,7 +9,7 @@ import shutil
|
|||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import cgi
|
import html
|
||||||
|
|
||||||
class BuildDesc:
|
class BuildDesc:
|
||||||
def __init__(self, prepend_envs=None, variables=None, build_type=None, generator=None):
|
def __init__(self, prepend_envs=None, variables=None, build_type=None, generator=None):
|
||||||
@@ -195,12 +195,12 @@ def generate_html_report(html_report_path, builds):
|
|||||||
for variable in variables:
|
for variable in variables:
|
||||||
build_types = sorted(build_types_by_variable[variable])
|
build_types = sorted(build_types_by_variable[variable])
|
||||||
nb_build_type = len(build_types_by_variable[variable])
|
nb_build_type = len(build_types_by_variable[variable])
|
||||||
th_vars.append('<th colspan="%d">%s</th>' % (nb_build_type, cgi.escape(' '.join(variable))))
|
th_vars.append('<th colspan="%d">%s</th>' % (nb_build_type, html.escape(' '.join(variable))))
|
||||||
for build_type in build_types:
|
for build_type in build_types:
|
||||||
th_build_types.append('<th>%s</th>' % cgi.escape(build_type))
|
th_build_types.append('<th>%s</th>' % html.escape(build_type))
|
||||||
tr_builds = []
|
tr_builds = []
|
||||||
for generator in sorted(builds_by_generator):
|
for generator in sorted(builds_by_generator):
|
||||||
tds = [ '<td>%s</td>\n' % cgi.escape(generator) ]
|
tds = [ '<td>%s</td>\n' % html.escape(generator) ]
|
||||||
for variable in variables:
|
for variable in variables:
|
||||||
build_types = sorted(build_types_by_variable[variable])
|
build_types = sorted(build_types_by_variable[variable])
|
||||||
for build_type in build_types:
|
for build_type in build_types:
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#ifndef JSON_ALLOCATOR_H_INCLUDED
|
#ifndef JSON_ALLOCATOR_H_INCLUDED
|
||||||
#define JSON_ALLOCATOR_H_INCLUDED
|
#define JSON_ALLOCATOR_H_INCLUDED
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -38,8 +39,16 @@ public:
|
|||||||
* The memory block is filled with zeroes before being released.
|
* The memory block is filled with zeroes before being released.
|
||||||
*/
|
*/
|
||||||
void deallocate(pointer p, size_type n) {
|
void deallocate(pointer p, size_type n) {
|
||||||
// memset_s is used because memset may be optimized away by the compiler
|
// These constructs will not be removed by the compiler during optimization,
|
||||||
|
// unlike memset.
|
||||||
|
#if defined(HAVE_MEMSET_S)
|
||||||
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
|
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
RtlSecureZeroMemory(p, n * sizeof(T));
|
||||||
|
#else
|
||||||
|
std::fill_n(reinterpret_cast<volatile unsigned char*>(p), n, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
// free using "global operator delete"
|
// free using "global operator delete"
|
||||||
::operator delete(p);
|
::operator delete(p);
|
||||||
}
|
}
|
||||||
|
@@ -127,7 +127,7 @@ using LargestUInt = UInt64;
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using Allocator =
|
using Allocator =
|
||||||
typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
|
typename std::conditional<JSONCPP_USE_SECURE_MEMORY, SecureAllocator<T>,
|
||||||
std::allocator<T>>::type;
|
std::allocator<T>>::type;
|
||||||
using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
|
using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
|
||||||
using IStringStream =
|
using IStringStream =
|
||||||
|
@@ -375,7 +375,7 @@ public:
|
|||||||
int compare(const Value& other) const;
|
int compare(const Value& other) const;
|
||||||
|
|
||||||
const char* asCString() const; ///< Embedded zeroes could cause you trouble!
|
const char* asCString() const; ///< Embedded zeroes could cause you trouble!
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
#if JSONCPP_USE_SECURE_MEMORY
|
||||||
unsigned getCStringLength() const; // Allows you to understand the length of
|
unsigned getCStringLength() const; // Allows you to understand the length of
|
||||||
// the CString
|
// the CString
|
||||||
#endif
|
#endif
|
||||||
|
@@ -9,17 +9,17 @@
|
|||||||
// 3. /CMakeLists.txt
|
// 3. /CMakeLists.txt
|
||||||
// IMPORTANT: also update the SOVERSION!!
|
// IMPORTANT: also update the SOVERSION!!
|
||||||
|
|
||||||
#define JSONCPP_VERSION_STRING "1.9.6"
|
#define JSONCPP_VERSION_STRING "1.9.7"
|
||||||
#define JSONCPP_VERSION_MAJOR 1
|
#define JSONCPP_VERSION_MAJOR 1
|
||||||
#define JSONCPP_VERSION_MINOR 9
|
#define JSONCPP_VERSION_MINOR 9
|
||||||
#define JSONCPP_VERSION_PATCH 6
|
#define JSONCPP_VERSION_PATCH 7
|
||||||
#define JSONCPP_VERSION_QUALIFIER
|
#define JSONCPP_VERSION_QUALIFIER
|
||||||
#define JSONCPP_VERSION_HEXA \
|
#define JSONCPP_VERSION_HEXA \
|
||||||
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
|
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
|
||||||
(JSONCPP_VERSION_PATCH << 8))
|
(JSONCPP_VERSION_PATCH << 8))
|
||||||
|
|
||||||
#if !defined(JSONCPP_USE_SECURE_MEMORY)
|
#if !defined(JSONCPP_USE_SECURE_MEMORY)
|
||||||
#define JSONCPP_USING_SECURE_MEMORY 0
|
#define JSONCPP_USE_SECURE_MEMORY 0
|
||||||
#endif
|
#endif
|
||||||
// If non-zero, the library zeroes any memory that it has allocated before
|
// If non-zero, the library zeroes any memory that it has allocated before
|
||||||
// it frees its memory.
|
// it frees its memory.
|
||||||
|
@@ -4,5 +4,3 @@
|
|||||||
@MESON_STATIC_TARGET@
|
@MESON_STATIC_TARGET@
|
||||||
|
|
||||||
include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )
|
include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )
|
||||||
|
|
||||||
check_required_components(JsonCpp)
|
|
||||||
|
@@ -9,7 +9,7 @@ project(
|
|||||||
# 2. /include/json/version.h
|
# 2. /include/json/version.h
|
||||||
# 3. /CMakeLists.txt
|
# 3. /CMakeLists.txt
|
||||||
# IMPORTANT: also update the SOVERSION!!
|
# IMPORTANT: also update the SOVERSION!!
|
||||||
version : '1.9.6',
|
version : '1.9.7',
|
||||||
default_options : [
|
default_options : [
|
||||||
'buildtype=release',
|
'buildtype=release',
|
||||||
'cpp_std=c++11',
|
'cpp_std=c++11',
|
||||||
@@ -50,7 +50,7 @@ jsoncpp_lib = library(
|
|||||||
'src/lib_json/json_value.cpp',
|
'src/lib_json/json_value.cpp',
|
||||||
'src/lib_json/json_writer.cpp',
|
'src/lib_json/json_writer.cpp',
|
||||||
]),
|
]),
|
||||||
soversion : 26,
|
soversion : 27,
|
||||||
install : true,
|
install : true,
|
||||||
include_directories : jsoncpp_include_directories,
|
include_directories : jsoncpp_include_directories,
|
||||||
cpp_args: dll_export_flag)
|
cpp_args: dll_export_flag)
|
||||||
|
@@ -143,7 +143,7 @@ if(BUILD_STATIC_LIBS)
|
|||||||
|
|
||||||
# avoid name clashes on windows as the shared import lib is also named jsoncpp.lib
|
# avoid name clashes on windows as the shared import lib is also named jsoncpp.lib
|
||||||
if(NOT DEFINED STATIC_SUFFIX AND BUILD_SHARED_LIBS)
|
if(NOT DEFINED STATIC_SUFFIX AND BUILD_SHARED_LIBS)
|
||||||
if (WIN32)
|
if (MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC"))
|
||||||
set(STATIC_SUFFIX "_static")
|
set(STATIC_SUFFIX "_static")
|
||||||
else()
|
else()
|
||||||
set(STATIC_SUFFIX "")
|
set(STATIC_SUFFIX "")
|
||||||
|
@@ -23,13 +23,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
|
|
||||||
#if !defined(sscanf)
|
|
||||||
#define sscanf std::sscanf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //__cplusplus
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
|
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
|
||||||
@@ -53,11 +46,7 @@ static size_t const stackLimit_g =
|
|||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
|
|
||||||
using CharReaderPtr = std::unique_ptr<CharReader>;
|
using CharReaderPtr = std::unique_ptr<CharReader>;
|
||||||
#else
|
|
||||||
using CharReaderPtr = std::auto_ptr<CharReader>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Implementation of class Features
|
// Implementation of class Features
|
||||||
// ////////////////////////////////
|
// ////////////////////////////////
|
||||||
|
@@ -87,7 +87,8 @@ template <typename T, typename U>
|
|||||||
static inline bool InRange(double d, T min, U max) {
|
static inline bool InRange(double d, T min, U max) {
|
||||||
// The casts can lose precision, but we are looking only for
|
// The casts can lose precision, but we are looking only for
|
||||||
// an approximate range. Might fail on edge cases though. ~cdunn
|
// an approximate range. Might fail on edge cases though. ~cdunn
|
||||||
return d >= static_cast<double>(min) && d <= static_cast<double>(max);
|
return d >= static_cast<double>(min) && d <= static_cast<double>(max) &&
|
||||||
|
!(static_cast<U>(d) == min && d != static_cast<double>(min));
|
||||||
}
|
}
|
||||||
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
||||||
static inline double integerToDouble(Json::UInt64 value) {
|
static inline double integerToDouble(Json::UInt64 value) {
|
||||||
@@ -101,7 +102,8 @@ template <typename T> static inline double integerToDouble(T value) {
|
|||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
static inline bool InRange(double d, T min, U max) {
|
static inline bool InRange(double d, T min, U max) {
|
||||||
return d >= integerToDouble(min) && d <= integerToDouble(max);
|
return d >= integerToDouble(min) && d <= integerToDouble(max) &&
|
||||||
|
!(static_cast<U>(d) == min && d != integerToDouble(min));
|
||||||
}
|
}
|
||||||
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
||||||
|
|
||||||
@@ -163,7 +165,7 @@ inline static void decodePrefixedString(bool isPrefixed, char const* prefixed,
|
|||||||
/** Free the string duplicated by
|
/** Free the string duplicated by
|
||||||
* duplicateStringValue()/duplicateAndPrefixStringValue().
|
* duplicateStringValue()/duplicateAndPrefixStringValue().
|
||||||
*/
|
*/
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
#if JSONCPP_USE_SECURE_MEMORY
|
||||||
static inline void releasePrefixedStringValue(char* value) {
|
static inline void releasePrefixedStringValue(char* value) {
|
||||||
unsigned length = 0;
|
unsigned length = 0;
|
||||||
char const* valueDecoded;
|
char const* valueDecoded;
|
||||||
@@ -178,10 +180,10 @@ static inline void releaseStringValue(char* value, unsigned length) {
|
|||||||
memset(value, 0, size);
|
memset(value, 0, size);
|
||||||
free(value);
|
free(value);
|
||||||
}
|
}
|
||||||
#else // !JSONCPP_USING_SECURE_MEMORY
|
#else // !JSONCPP_USE_SECURE_MEMORY
|
||||||
static inline void releasePrefixedStringValue(char* value) { free(value); }
|
static inline void releasePrefixedStringValue(char* value) { free(value); }
|
||||||
static inline void releaseStringValue(char* value, unsigned) { free(value); }
|
static inline void releaseStringValue(char* value, unsigned) { free(value); }
|
||||||
#endif // JSONCPP_USING_SECURE_MEMORY
|
#endif // JSONCPP_USE_SECURE_MEMORY
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
@@ -599,7 +601,7 @@ const char* Value::asCString() const {
|
|||||||
return this_str;
|
return this_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
#if JSONCPP_USE_SECURE_MEMORY
|
||||||
unsigned Value::getCStringLength() const {
|
unsigned Value::getCStringLength() const {
|
||||||
JSON_ASSERT_MESSAGE(type() == stringValue,
|
JSON_ASSERT_MESSAGE(type() == stringValue,
|
||||||
"in Json::Value::asCString(): requires stringValue");
|
"in Json::Value::asCString(): requires stringValue");
|
||||||
@@ -682,7 +684,7 @@ Value::UInt Value::asUInt() const {
|
|||||||
JSON_ASSERT_MESSAGE(isUInt(), "LargestUInt out of UInt range");
|
JSON_ASSERT_MESSAGE(isUInt(), "LargestUInt out of UInt range");
|
||||||
return UInt(value_.uint_);
|
return UInt(value_.uint_);
|
||||||
case realValue:
|
case realValue:
|
||||||
JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt),
|
JSON_ASSERT_MESSAGE(InRange(value_.real_, 0u, maxUInt),
|
||||||
"double out of UInt range");
|
"double out of UInt range");
|
||||||
return UInt(value_.real_);
|
return UInt(value_.real_);
|
||||||
case nullValue:
|
case nullValue:
|
||||||
@@ -705,6 +707,11 @@ Value::Int64 Value::asInt64() const {
|
|||||||
JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range");
|
JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range");
|
||||||
return Int64(value_.uint_);
|
return Int64(value_.uint_);
|
||||||
case realValue:
|
case realValue:
|
||||||
|
// If the double value is in proximity to minInt64, it will be rounded to
|
||||||
|
// minInt64. The correct value in this scenario is indeterminable
|
||||||
|
JSON_ASSERT_MESSAGE(
|
||||||
|
value_.real_ != minInt64,
|
||||||
|
"Double value is minInt64, precise value cannot be determined");
|
||||||
JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64),
|
JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64),
|
||||||
"double out of Int64 range");
|
"double out of Int64 range");
|
||||||
return Int64(value_.real_);
|
return Int64(value_.real_);
|
||||||
@@ -726,7 +733,7 @@ Value::UInt64 Value::asUInt64() const {
|
|||||||
case uintValue:
|
case uintValue:
|
||||||
return UInt64(value_.uint_);
|
return UInt64(value_.uint_);
|
||||||
case realValue:
|
case realValue:
|
||||||
JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt64),
|
JSON_ASSERT_MESSAGE(InRange(value_.real_, 0u, maxUInt64),
|
||||||
"double out of UInt64 range");
|
"double out of UInt64 range");
|
||||||
return UInt64(value_.real_);
|
return UInt64(value_.real_);
|
||||||
case nullValue:
|
case nullValue:
|
||||||
@@ -837,7 +844,7 @@ bool Value::isConvertibleTo(ValueType other) const {
|
|||||||
type() == booleanValue || type() == nullValue;
|
type() == booleanValue || type() == nullValue;
|
||||||
case uintValue:
|
case uintValue:
|
||||||
return isUInt() ||
|
return isUInt() ||
|
||||||
(type() == realValue && InRange(value_.real_, 0, maxUInt)) ||
|
(type() == realValue && InRange(value_.real_, 0u, maxUInt)) ||
|
||||||
type() == booleanValue || type() == nullValue;
|
type() == booleanValue || type() == nullValue;
|
||||||
case realValue:
|
case realValue:
|
||||||
return isNumeric() || type() == booleanValue || type() == nullValue;
|
return isNumeric() || type() == booleanValue || type() == nullValue;
|
||||||
@@ -1311,8 +1318,12 @@ bool Value::isInt64() const {
|
|||||||
// Note that maxInt64 (= 2^63 - 1) is not exactly representable as a
|
// Note that maxInt64 (= 2^63 - 1) is not exactly representable as a
|
||||||
// double, so double(maxInt64) will be rounded up to 2^63. Therefore we
|
// double, so double(maxInt64) will be rounded up to 2^63. Therefore we
|
||||||
// require the value to be strictly less than the limit.
|
// require the value to be strictly less than the limit.
|
||||||
return value_.real_ >= double(minInt64) &&
|
// minInt64 is -2^63 which can be represented as a double, but since double
|
||||||
value_.real_ < double(maxInt64) && IsIntegral(value_.real_);
|
// values in its proximity are also rounded to -2^63, we require the value
|
||||||
|
// to be strictly greater than the limit to avoid returning 'true' for
|
||||||
|
// values that are not in the range
|
||||||
|
return value_.real_ > double(minInt64) && value_.real_ < double(maxInt64) &&
|
||||||
|
IsIntegral(value_.real_);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1350,7 +1361,11 @@ bool Value::isIntegral() const {
|
|||||||
// Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
|
// Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
|
||||||
// double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
|
// double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
|
||||||
// require the value to be strictly less than the limit.
|
// require the value to be strictly less than the limit.
|
||||||
return value_.real_ >= double(minInt64) &&
|
// minInt64 is -2^63 which can be represented as a double, but since double
|
||||||
|
// values in its proximity are also rounded to -2^63, we require the value
|
||||||
|
// to be strictly greater than the limit to avoid returning 'true' for
|
||||||
|
// values that are not in the range
|
||||||
|
return value_.real_ > double(minInt64) &&
|
||||||
value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
|
value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
|
||||||
#else
|
#else
|
||||||
return value_.real_ >= minInt && value_.real_ <= maxUInt &&
|
return value_.real_ >= minInt && value_.real_ <= maxUInt &&
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -17,67 +19,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#if !defined(isnan)
|
|
||||||
#define isnan std::isnan
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(isfinite)
|
|
||||||
#define isfinite std::isfinite
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#if !defined(isnan)
|
|
||||||
#include <float.h>
|
|
||||||
#define isnan _isnan
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(isfinite)
|
|
||||||
#include <float.h>
|
|
||||||
#define isfinite _finite
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
|
|
||||||
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
|
|
||||||
#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
|
|
||||||
|
|
||||||
#endif //_MSC_VER
|
|
||||||
|
|
||||||
#if defined(__sun) && defined(__SVR4) // Solaris
|
|
||||||
#if !defined(isfinite)
|
|
||||||
#include <ieeefp.h>
|
|
||||||
#define isfinite finite
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__hpux)
|
|
||||||
#if !defined(isfinite)
|
|
||||||
#if defined(__ia64) && !defined(finite)
|
|
||||||
#define isfinite(x) \
|
|
||||||
((sizeof(x) == sizeof(float) ? _Isfinitef(x) : _IsFinite(x)))
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(isnan)
|
|
||||||
// IEEE standard states that NaN values will not compare to themselves
|
|
||||||
#define isnan(x) ((x) != (x))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(__APPLE__)
|
|
||||||
#if !defined(isfinite)
|
|
||||||
#define isfinite finite
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
// Disable warning about strdup being deprecated.
|
// Disable warning about strdup being deprecated.
|
||||||
#pragma warning(disable : 4996)
|
#pragma warning(disable : 4996)
|
||||||
@@ -85,11 +26,7 @@
|
|||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
|
|
||||||
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
|
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
|
||||||
#else
|
|
||||||
using StreamWriterPtr = std::auto_ptr<StreamWriter>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
String valueToString(LargestInt value) {
|
String valueToString(LargestInt value) {
|
||||||
UIntToStringBuffer buffer;
|
UIntToStringBuffer buffer;
|
||||||
@@ -129,12 +66,12 @@ String valueToString(double value, bool useSpecialFloats,
|
|||||||
// Print into the buffer. We need not request the alternative representation
|
// Print into the buffer. We need not request the alternative representation
|
||||||
// that always has a decimal point because JSON doesn't distinguish the
|
// that always has a decimal point because JSON doesn't distinguish the
|
||||||
// concepts of reals and integers.
|
// concepts of reals and integers.
|
||||||
if (!isfinite(value)) {
|
if (!std::isfinite(value)) {
|
||||||
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
|
if (std::isnan(value))
|
||||||
{"null", "-1e+9999", "1e+9999"}};
|
return useSpecialFloats ? "NaN" : "null";
|
||||||
return reps[useSpecialFloats ? 0 : 1][isnan(value) ? 0
|
if (value < 0)
|
||||||
: (value < 0) ? 1
|
return useSpecialFloats ? "-Infinity" : "-1e+9999";
|
||||||
: 2];
|
return useSpecialFloats ? "Infinity" : "1e+9999";
|
||||||
}
|
}
|
||||||
|
|
||||||
String buffer(size_t(36), '\0');
|
String buffer(size_t(36), '\0');
|
||||||
|
@@ -410,7 +410,7 @@ Json::String ToJsonString(const char* toConvert) {
|
|||||||
|
|
||||||
Json::String ToJsonString(Json::String in) { return in; }
|
Json::String ToJsonString(Json::String in) { return in; }
|
||||||
|
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
#if JSONCPP_USE_SECURE_MEMORY
|
||||||
Json::String ToJsonString(std::string in) {
|
Json::String ToJsonString(std::string in) {
|
||||||
return Json::String(in.data(), in.data() + in.length());
|
return Json::String(in.data(), in.data() + in.length());
|
||||||
}
|
}
|
||||||
|
@@ -185,7 +185,7 @@ TestResult& checkEqual(TestResult& result, T expected, U actual,
|
|||||||
|
|
||||||
Json::String ToJsonString(const char* toConvert);
|
Json::String ToJsonString(const char* toConvert);
|
||||||
Json::String ToJsonString(Json::String in);
|
Json::String ToJsonString(Json::String in);
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
#if JSONCPP_USE_SECURE_MEMORY
|
||||||
Json::String ToJsonString(std::string in);
|
Json::String ToJsonString(std::string in);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -1191,15 +1191,13 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, integers) {
|
|||||||
JSONTEST_ASSERT_EQUAL(true, val.asBool());
|
JSONTEST_ASSERT_EQUAL(true, val.asBool());
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("-9223372036854775808", val.asString());
|
JSONTEST_ASSERT_STRING_EQUAL("-9223372036854775808", val.asString());
|
||||||
|
|
||||||
// int64 min (floating point constructor). Note that kint64min *is* exactly
|
// int64 min (floating point constructor). Since double values in proximity of
|
||||||
// representable as a double.
|
// kint64min are rounded to kint64min, we don't check for conversion to int64.
|
||||||
val = Json::Value(double(kint64min));
|
val = Json::Value(double(kint64min));
|
||||||
|
|
||||||
JSONTEST_ASSERT_EQUAL(Json::realValue, val.type());
|
JSONTEST_ASSERT_EQUAL(Json::realValue, val.type());
|
||||||
|
|
||||||
checks = IsCheck();
|
checks = IsCheck();
|
||||||
checks.isInt64_ = true;
|
|
||||||
checks.isIntegral_ = true;
|
|
||||||
checks.isDouble_ = true;
|
checks.isDouble_ = true;
|
||||||
checks.isNumeric_ = true;
|
checks.isNumeric_ = true;
|
||||||
JSONTEST_ASSERT_PRED(checkIs(val, checks));
|
JSONTEST_ASSERT_PRED(checkIs(val, checks));
|
||||||
@@ -1208,8 +1206,6 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, integers) {
|
|||||||
JSONTEST_ASSERT(!val.isConvertibleTo(Json::intValue));
|
JSONTEST_ASSERT(!val.isConvertibleTo(Json::intValue));
|
||||||
JSONTEST_ASSERT(!val.isConvertibleTo(Json::uintValue));
|
JSONTEST_ASSERT(!val.isConvertibleTo(Json::uintValue));
|
||||||
|
|
||||||
JSONTEST_ASSERT_EQUAL(kint64min, val.asInt64());
|
|
||||||
JSONTEST_ASSERT_EQUAL(kint64min, val.asLargestInt());
|
|
||||||
JSONTEST_ASSERT_EQUAL(-9223372036854775808.0, val.asDouble());
|
JSONTEST_ASSERT_EQUAL(-9223372036854775808.0, val.asDouble());
|
||||||
JSONTEST_ASSERT_EQUAL(-9223372036854775808.0, val.asFloat());
|
JSONTEST_ASSERT_EQUAL(-9223372036854775808.0, val.asFloat());
|
||||||
JSONTEST_ASSERT_EQUAL(true, val.asBool());
|
JSONTEST_ASSERT_EQUAL(true, val.asBool());
|
||||||
|
Reference in New Issue
Block a user