Go to the documentation of this file.
78 #ifndef JSON_IS_AMALGAMATION
79 #error "Compile with -I PATH_TO_JSON_DIRECTORY"
92 #ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
93 #define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
111 result[0] =
static_cast<char>(cp);
112 }
else if (cp <= 0x7FF) {
114 result[1] =
static_cast<char>(0x80 | (0x3f & cp));
115 result[0] =
static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
116 }
else if (cp <= 0xFFFF) {
118 result[2] =
static_cast<char>(0x80 | (0x3f & cp));
119 result[1] =
static_cast<char>(0x80 | (0x3f & (cp >> 6)));
120 result[0] =
static_cast<char>(0xE0 | (0xf & (cp >> 12)));
121 }
else if (cp <= 0x10FFFF) {
123 result[3] =
static_cast<char>(0x80 | (0x3f & cp));
124 result[2] =
static_cast<char>(0x80 | (0x3f & (cp >> 6)));
125 result[1] =
static_cast<char>(0x80 | (0x3f & (cp >> 12)));
126 result[0] =
static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
152 *--current =
static_cast<signed char>(
value % 10U +
static_cast<unsigned>(
'0'));
154 }
while (
value != 0);
173 #endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED
193 #if !defined(JSON_IS_AMALGAMATION)
194 #include <json/assertions.h>
195 #include <json/reader.h>
196 #include <json/value.h>
197 #include "json_tool.h"
198 #endif // if !defined(JSON_IS_AMALGAMATION)
209 #if defined(_MSC_VER)
210 #if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
211 #define snprintf sprintf_s
212 #elif _MSC_VER >= 1900 // VC++ 14.0 and above
213 #define snprintf std::snprintf
215 #define snprintf _snprintf
217 #elif defined(__ANDROID__) || defined(__QNXNTO__)
218 #define snprintf snprintf
219 #elif __cplusplus >= 201103L
220 #define snprintf std::snprintf
223 #if defined(__QNXNTO__)
224 #define sscanf std::sscanf
227 #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
229 #pragma warning(disable : 4996)
237 #if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
247 : allowComments_(
true), strictRoot_(
false),
248 allowDroppedNullPlaceholders_(
false), allowNumericKeys_(
false) {}
275 : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
276 lastValue_(), commentsBefore_(), features_(
Features::all()),
277 collectComments_() {}
280 : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
281 lastValue_(), commentsBefore_(), features_(features), collectComments_() {
301 std::getline(sin, doc, (
char)EOF);
302 return parse(doc,
root, collectComments);
308 bool collectComments) {
310 collectComments =
false;
332 if (!
root.isArray() && !
root.isObject()) {
339 "A valid JSON document must be either an array or an object value.",
357 bool successful =
true;
364 switch (token.
type_) {
419 return addError(
"Syntax error: value, object or array expected.", token);
515 if (c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n')
525 int index = patternLength;
536 bool successful =
false;
560 while (current !=
end) {
563 if (current !=
end && *current ==
'\n')
616 while (c >=
'0' && c <=
'9')
621 while (c >=
'0' && c <=
'9')
625 if (c ==
'e' || c ==
'E') {
627 if (c ==
'+' || c ==
'-')
629 while (c >=
'0' && c <=
'9')
653 bool initialTokenOk =
true;
690 "Missing ',' or '}' in object declaration", comma,
tokenObjectEnd);
692 bool finalizeTokenOk =
true;
730 if (!
ok || badTokenType) {
732 "Missing ',' or ']' in array declaration", token,
tokenArrayEnd);
755 bool isNegative = *current ==
'-';
764 while (current < token.
end_) {
766 if (c < '0' || c >
'9')
769 if (
value >= threshold) {
774 if (
value > threshold || current != token.
end_ ||
775 digit > maxIntegerValue % 10) {
781 if (isNegative &&
value == maxIntegerValue)
805 std::istringstream is(
buffer);
808 "' is not a number.",
818 Value decoded(decoded_string);
826 decoded.reserve(token.
end_ - token.
start_ - 2);
829 while (current !=
end) {
833 else if (c ==
'\\') {
835 return addError(
"Empty escape sequence in string", token, current);
863 unsigned int unicode;
869 return addError(
"Bad escape sequence in string", token, current);
881 unsigned int& unicode) {
885 if (unicode >= 0xD800 && unicode <= 0xDBFF) {
887 if (
end - current < 6)
889 "additional six characters expected to parse unicode surrogate pair.",
892 unsigned int surrogatePair;
893 if (*(current++) ==
'\\' && *(current++) ==
'u') {
895 unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
899 return addError(
"expecting another \\u token to begin the second half of "
900 "a unicode surrogate pair",
910 unsigned int& unicode) {
911 if (
end - current < 4)
913 "Bad unicode escape sequence in string: four digits expected.",
920 if (c >=
'0' && c <=
'9')
922 else if (c >=
'a' && c <=
'f')
923 unicode += c -
'a' + 10;
924 else if (c >=
'A' && c <=
'F')
925 unicode += c -
'A' + 10;
928 "Bad unicode escape sequence in string: hexadecimal digit expected.",
946 int errorCount = int(
errors_.size());
982 if (*current ==
'\n')
984 lastLineStart = current;
986 }
else if (c ==
'\n') {
987 lastLineStart = current;
992 column = int(
location - lastLineStart) + 1;
999 char buffer[18 + 16 + 16 + 1];
1011 for (Errors::const_iterator itError =
errors_.begin();
1017 formattedMessage +=
" " +
error.message_ +
"\n";
1022 return formattedMessage;
1026 std::vector<Reader::StructuredError> allErrors;
1027 for (Errors::const_iterator itError =
errors_.begin();
1035 allErrors.push_back(structured);
1114 bool parse(
const char* beginDoc,
1117 bool collectComments =
true);
1185 unsigned int& unicode);
1189 unsigned int& unicode);
1223 : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
1224 lastValue_(), commentsBefore_(),
1226 features_(features), collectComments_() {
1232 bool collectComments) {
1234 collectComments =
false;
1255 addError(
"Extra non-whitespace after JSON value.", token);
1262 if (!
root.isArray() && !
root.isObject()) {
1267 token.
end_ = endDoc;
1269 "A valid JSON document must be either an array or an object value.",
1282 bool successful =
true;
1289 switch (token.
type_) {
1330 Value v(std::numeric_limits<double>::quiet_NaN());
1338 Value v(std::numeric_limits<double>::infinity());
1346 Value v(-std::numeric_limits<double>::infinity());
1368 return addError(
"Syntax error: value, object or array expected.", token);
1493 if (c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n')
1503 int index = patternLength;
1514 bool successful =
false;
1573 if (checkInf &&
p !=
end_ && *
p ==
'I') {
1579 while (c >=
'0' && c <=
'9')
1584 while (c >=
'0' && c <=
'9')
1588 if (c ==
'e' || c ==
'E') {
1590 if (c ==
'+' || c ==
'-')
1592 while (c >=
'0' && c <=
'9')
1629 bool initialTokenOk =
true;
1632 if (!initialTokenOk)
1672 "Missing ',' or '}' in object declaration", comma,
tokenObjectEnd);
1674 bool finalizeTokenOk =
true;
1712 if (!
ok || badTokenType) {
1714 "Missing ',' or ']' in array declaration", token,
tokenArrayEnd);
1737 bool isNegative = *current ==
'-';
1746 while (current < token.
end_) {
1747 Char c = *current++;
1748 if (c < '0' || c >
'9')
1751 if (
value >= threshold) {
1756 if (
value > threshold || current != token.
end_ ||
1757 digit > maxIntegerValue % 10) {
1784 const int bufferSize = 32;
1790 return addError(
"Unable to parse token length", token);
1800 if (
length <= bufferSize) {
1812 "' is not a number.",
1822 Value decoded(decoded_string);
1830 decoded.reserve(token.
end_ - token.
start_ - 2);
1833 while (current !=
end) {
1834 Char c = *current++;
1837 else if (c ==
'\\') {
1839 return addError(
"Empty escape sequence in string", token, current);
1867 unsigned int unicode;
1873 return addError(
"Bad escape sequence in string", token, current);
1885 unsigned int& unicode) {
1889 if (unicode >= 0xD800 && unicode <= 0xDBFF) {
1891 if (
end - current < 6)
1893 "additional six characters expected to parse unicode surrogate pair.",
1896 unsigned int surrogatePair;
1897 if (*(current++) ==
'\\' && *(current++) ==
'u') {
1899 unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
1903 return addError(
"expecting another \\u token to begin the second half of "
1904 "a unicode surrogate pair",
1914 unsigned int& unicode) {
1915 if (
end - current < 4)
1917 "Bad unicode escape sequence in string: four digits expected.",
1922 Char c = *current++;
1924 if (c >=
'0' && c <=
'9')
1926 else if (c >=
'a' && c <=
'f')
1927 unicode += c -
'a' + 10;
1928 else if (c >=
'A' && c <=
'F')
1929 unicode += c -
'A' + 10;
1932 "Bad unicode escape sequence in string: hexadecimal digit expected.",
1950 int errorCount = int(
errors_.size());
1979 int& column)
const {
1984 Char c = *current++;
1986 if (*current ==
'\n')
1988 lastLineStart = current;
1990 }
else if (c ==
'\n') {
1991 lastLineStart = current;
1996 column = int(
location - lastLineStart) + 1;
2003 char buffer[18 + 16 + 16 + 1];
2010 for (Errors::const_iterator itError =
errors_.begin();
2016 formattedMessage +=
" " +
error.message_ +
"\n";
2021 return formattedMessage;
2025 std::vector<OurReader::StructuredError> allErrors;
2026 for (Errors::const_iterator itError =
errors_.begin();
2034 allErrors.push_back(structured);
2084 bool collectComments,
2090 char const* beginDoc,
char const* endDoc,
2123 valid_keys->clear();
2124 valid_keys->insert(
"collectComments");
2125 valid_keys->insert(
"allowComments");
2126 valid_keys->insert(
"strictRoot");
2127 valid_keys->insert(
"allowDroppedNullPlaceholders");
2128 valid_keys->insert(
"allowNumericKeys");
2129 valid_keys->insert(
"allowSingleQuotes");
2130 valid_keys->insert(
"stackLimit");
2131 valid_keys->insert(
"failIfExtra");
2132 valid_keys->insert(
"rejectDupKeys");
2133 valid_keys->insert(
"allowSpecialFloats");
2138 if (!invalid) invalid = &my_invalid;
2140 std::set<std::string> valid_keys;
2143 size_t n = keys.size();
2144 for (
size_t i = 0;
i <
n; ++
i) {
2146 if (valid_keys.find(
key) == valid_keys.end()) {
2150 return 0u == inv.
size();
2160 (*settings)[
"allowComments"] =
false;
2161 (*settings)[
"strictRoot"] =
true;
2162 (*settings)[
"allowDroppedNullPlaceholders"] =
false;
2163 (*settings)[
"allowNumericKeys"] =
false;
2164 (*settings)[
"allowSingleQuotes"] =
false;
2165 (*settings)[
"stackLimit"] = 1000;
2166 (*settings)[
"failIfExtra"] =
true;
2167 (*settings)[
"rejectDupKeys"] =
true;
2168 (*settings)[
"allowSpecialFloats"] =
false;
2175 (*settings)[
"collectComments"] =
true;
2176 (*settings)[
"allowComments"] =
true;
2177 (*settings)[
"strictRoot"] =
false;
2178 (*settings)[
"allowDroppedNullPlaceholders"] =
false;
2179 (*settings)[
"allowNumericKeys"] =
false;
2180 (*settings)[
"allowSingleQuotes"] =
false;
2181 (*settings)[
"stackLimit"] = 1000;
2182 (*settings)[
"failIfExtra"] =
false;
2183 (*settings)[
"rejectDupKeys"] =
false;
2184 (*settings)[
"allowSpecialFloats"] =
false;
2195 std::ostringstream ssin;
2196 ssin << sin.rdbuf();
2198 char const*
begin = doc.data();
2199 char const*
end =
begin + doc.size();
2211 "Error from reader: %s",
2252 : current_(), isNull_(
true) {
2256 const Value::ObjectValues::iterator& current)
2257 : current_(current), isNull_(
false) {}
2273 #ifdef JSON_USE_CPPTL_SMALLMAP
2312 const Value::CZString czstring = (*current_).first;
2313 if (czstring.data()) {
2314 if (czstring.isStaticString())
2316 return Value(czstring.data(), czstring.data() + czstring.length());
2318 return Value(czstring.index());
2322 const Value::CZString czstring = (*current_).first;
2323 if (!czstring.data())
2324 return czstring.index();
2337 const char* cname = (*current_).first.data();
2338 return cname ? cname :
"";
2342 const char* cname = (*current_).first.data();
2347 *
end = cname + (*current_).first.length();
2362 const Value::ObjectValues::iterator& current)
2420 #if !defined(JSON_IS_AMALGAMATION)
2421 #include <json/assertions.h>
2422 #include <json/value.h>
2423 #include <json/writer.h>
2424 #endif // if !defined(JSON_IS_AMALGAMATION)
2430 #ifdef JSON_USE_CPPTL
2431 #include <cpptl/conststring.h>
2434 #include <algorithm>
2436 #define JSON_ASSERT_UNREACHABLE assert(false)
2443 #if defined(__ARMEL__)
2444 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
2446 #define ALIGNAS(byte_alignment)
2448 static const unsigned char ALIGNAS(8) kNull[sizeof(
Value)] = { 0 };
2456 #if defined(JSON_HAS_INT64)
2463 static const double maxUInt64AsDouble = 18446744073709551615.0;
2464 #endif // defined(JSON_HAS_INT64)
2469 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
2470 template <
typename T,
typename U>
2472 return d >= min &&
d <= max;
2474 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
2479 template <
typename T>
static inline double integerToDouble(
T value) {
2480 return static_cast<double>(
value);
2483 template <
typename T,
typename U>
2484 static inline bool InRange(
double d,
T min, U max) {
2485 return d >= integerToDouble(min) &&
d <= integerToDouble(max);
2487 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
2503 char* newString =
static_cast<char*
>(malloc(
length + 1));
2504 if (newString ==
NULL) {
2506 "in Json::Value::duplicateStringValue(): "
2507 "Failed to allocate string value buffer");
2523 "in Json::Value::duplicateAndPrefixStringValue(): "
2524 "length too big for prefixing");
2525 unsigned actualLength =
length +
static_cast<unsigned>(
sizeof(unsigned)) + 1U;
2526 char* newString =
static_cast<char*
>(malloc(actualLength));
2527 if (newString == 0) {
2529 "in Json::Value::duplicateAndPrefixStringValue(): "
2530 "Failed to allocate string value buffer");
2532 *
reinterpret_cast<unsigned*
>(newString) =
length;
2533 memcpy(newString +
sizeof(
unsigned),
value,
length);
2534 newString[actualLength - 1U] = 0;
2538 bool isPrefixed,
char const* prefixed,
2542 *
length =
static_cast<unsigned>(strlen(prefixed));
2545 *
length = *
reinterpret_cast<unsigned const*
>(prefixed);
2546 *
value = prefixed +
sizeof(unsigned);
2562 #if !defined(JSON_IS_AMALGAMATION)
2564 #include "json_valueiterator.inl"
2565 #endif // if !defined(JSON_IS_AMALGAMATION)
2576 return msg_.c_str();
2615 text[0] ==
'\0' || text[0] ==
'/',
2616 "in Json::Value::setComment(): Comments must start with /");
2642 : cstr_(other.storage_.policy_ != noDuplication && other.cstr_ != 0
2652 #if JSON_HAS_RVALUE_REFERENCES
2655 other.cstr_ =
nullptr;
2660 if (cstr_ && storage_.policy_ == duplicate)
2678 unsigned this_len = this->storage_.length_;
2680 unsigned min_len = std::min(this_len, other_len);
2681 int comp = memcmp(this->cstr_, other.
cstr_, min_len);
2682 if (comp < 0)
return true;
2683 if (comp > 0)
return false;
2684 return (this_len < other_len);
2691 unsigned this_len = this->storage_.length_;
2693 if (this_len != other_len)
return false;
2694 int comp = memcmp(this->cstr_, other.
cstr_, this_len);
2753 #if defined(JSON_HAS_INT64)
2762 #endif // defined(JSON_HAS_INT64)
2791 #ifdef JSON_USE_CPPTL
2847 #if JSON_HAS_RVALUE_REFERENCES
2914 return typeDelta < 0 ?
true :
false;
2934 char const* this_str;
2935 char const* other_str;
2938 unsigned min_len = std::min(this_len, other_len);
2939 int comp = memcmp(this_str, other_str, min_len);
2940 if (comp < 0)
return true;
2941 if (comp > 0)
return false;
2942 return (this_len < other_len);
2968 int temp = other.
type_;
2989 char const* this_str;
2990 char const* other_str;
2993 if (this_len != other_len)
return false;
2994 int comp = memcmp(this_str, other_str, this_len);
3011 "in Json::Value::asCString(): requires stringValue");
3014 char const* this_str;
3036 char const* this_str;
3053 #ifdef JSON_USE_CPPTL
3054 CppTL::ConstString Value::asConstString()
const {
3059 return CppTL::ConstString(
str,
len);
3073 "double out of Int range");
3095 "double out of UInt range");
3107 #if defined(JSON_HAS_INT64)
3118 "double out of Int64 range");
3139 "double out of UInt64 range");
3150 #endif // if defined(JSON_HAS_INT64)
3153 #if defined(JSON_NO_INT64)
3161 #if defined(JSON_NO_INT64)
3173 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
3175 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
3177 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
3195 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
3197 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
3199 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
3276 ObjectValues::const_iterator itLast =
value_.
map_->end();
3278 return (*itLast).first.index() + 1;
3290 return size() == 0u;
3300 "in Json::Value::clear(): requires complex value");
3315 "in Json::Value::resize(): requires arrayValue");
3321 else if (newSize > oldSize)
3322 (*this)[newSize - 1];
3327 assert(
size() == newSize);
3334 "in Json::Value::operator[](ArrayIndex): requires arrayValue");
3340 return (*it).second;
3344 return (*it).second;
3350 "in Json::Value::operator[](int index): index cannot be negative");
3357 "in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
3364 return (*it).second;
3370 "in Json::Value::operator[](int index) const: index cannot be negative");
3388 "in Json::Value::resolveReference(): requires objectValue");
3393 ObjectValues::iterator
it =
value_.
map_->lower_bound(actualKey);
3394 if (
it !=
value_.
map_->end() && (*it).first == actualKey)
3395 return (*it).second;
3408 "in Json::Value::resolveReference(key, end): requires objectValue");
3413 ObjectValues::iterator
it =
value_.
map_->lower_bound(actualKey);
3414 if (
it !=
value_.
map_->end() && (*it).first == actualKey)
3415 return (*it).second;
3434 "in Json::Value::find(key, end, found): requires objectValue or nullValue");
3437 ObjectValues::const_iterator
it =
value_.
map_->find(actualKey);
3439 return &(*it).second;
3466 #ifdef JSON_USE_CPPTL
3491 return get(
key.data(),
key.data() +
key.length(), defaultValue);
3501 ObjectValues::iterator
it =
value_.
map_->find(actualKey);
3504 *removed =
it->second;
3519 "in Json::Value::removeMember(): requires objectValue");
3541 *removed =
it->second;
3550 ObjectValues::iterator itLast =
value_.
map_->find(keyLast);
3555 #ifdef JSON_USE_CPPTL
3557 const Value& defaultValue)
const {
3558 return get(
key.c_str(),
key.end_c_str(), defaultValue);
3576 #ifdef JSON_USE_CPPTL
3585 "in Json::Value::getMemberNames(), value must be objectValue");
3590 ObjectValues::const_iterator
it =
value_.
map_->begin();
3591 ObjectValues::const_iterator itEnd =
value_.
map_->end();
3592 for (;
it != itEnd; ++
it) {
3594 (*it).first.length()));
3625 double integral_part;
3626 return modf(
d, &integral_part) == 0.0;
3664 #if defined(JSON_HAS_INT64)
3679 #endif // JSON_HAS_INT64
3684 #if defined(JSON_HAS_INT64)
3699 #endif // JSON_HAS_INT64
3704 #if defined(JSON_HAS_INT64)
3724 if ((
len > 0) && (comment[
len-1] ==
'\n')) {
3732 setComment(comment, strlen(comment), placement);
3736 setComment(comment.c_str(), comment.length(), placement);
3759 return writer.
write(*
this);
3823 : key_(
key),
index_(), kind_(kindKey) {}
3826 : key_(
key.c_str()),
index_(), kind_(kindKey) {}
3847 const char* current =
path.c_str();
3848 const char*
end = current +
path.length();
3849 InArgs::const_iterator itInArg = in.begin();
3850 while (current !=
end) {
3851 if (*current ==
'[') {
3853 if (*current ==
'%')
3857 for (; current !=
end && *current >=
'0' && *current <=
'9'; ++current)
3861 if (current ==
end || *current++ !=
']')
3863 }
else if (*current ==
'%') {
3866 }
else if (*current ==
'.') {
3869 const char* beginName = current;
3870 while (current !=
end && !strchr(
"[.", *current))
3879 InArgs::const_iterator& itInArg,
3881 if (itInArg == in.end()) {
3883 }
else if ((*itInArg)->kind_ != kind) {
3886 args_.push_back(**itInArg);
3902 node = &((*node)[arg.
index_]);
3907 node = &((*node)[arg.
key_]);
3923 return defaultValue;
3924 node = &((*node)[arg.
index_]);
3927 return defaultValue;
3928 node = &((*node)[arg.
key_]);
3930 return defaultValue;
3944 node = &((*node)[arg.
index_]);
3949 node = &((*node)[arg.
key_]);
3975 #if !defined(JSON_IS_AMALGAMATION)
3976 #include <json/writer.h>
3977 #include "json_tool.h"
3978 #endif // if !defined(JSON_IS_AMALGAMATION)
3988 #if defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1800 // Between VC++ 6.0 and VC++ 11.0
3990 #define isfinite _finite
3991 #elif defined(__sun) && defined(__SVR4) //Solaris
3992 #if !defined(isfinite)
3994 #define isfinite finite
3997 #if !defined(isfinite)
3999 #define isfinite finite
4001 #elif defined(__hpux)
4002 #if !defined(isfinite)
4003 #if defined(__ia64) && !defined(finite)
4004 #define isfinite(x) ((sizeof(x) == sizeof(float) ? \
4005 _Isfinitef(x) : _IsFinite(x)))
4008 #define isfinite finite
4013 #if !(defined(__QNXNTO__)) // QNX already defines isfinite
4014 #define isfinite std::isfinite
4018 #if defined(_MSC_VER)
4019 #if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
4020 #define snprintf sprintf_s
4021 #elif _MSC_VER >= 1900 // VC++ 14.0 and above
4022 #define snprintf std::snprintf
4024 #define snprintf _snprintf
4026 #elif defined(__ANDROID__) || defined(__QNXNTO__)
4027 #define snprintf snprintf
4028 #elif __cplusplus >= 201103L
4029 #define snprintf std::snprintf
4032 #if defined(__BORLANDC__)
4034 #define isfinite _finite
4035 #define snprintf _snprintf
4038 #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
4040 #pragma warning(disable : 4996)
4045 #if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
4075 }
else if (
value < 0) {
4081 assert(current >=
buffer);
4089 assert(current >=
buffer);
4093 #if defined(JSON_HAS_INT64)
4103 #endif // # if defined(JSON_HAS_INT64)
4111 char formatString[6];
4112 sprintf(formatString,
"%%.%dg",
precision);
4123 }
else if (
value < 0) {
4143 if (strpbrk(
value,
"\"\\\b\f\n\r\t") ==
NULL &&
4149 std::string::size_type maxsize =
4150 strlen(
value) * 2 + 3;
4152 result.reserve(maxsize);
4154 for (
const char* c =
value; *c != 0; ++c) {
4187 std::ostringstream oss;
4188 oss <<
"\\u" << std::hex << std::uppercase << std::setfill(
'0')
4189 << std::setw(4) <<
static_cast<int>(*c);
4190 result += oss.str();
4202 static char const*
strnpbrk(
char const* s,
char const* accept,
size_t n) {
4203 assert((
s || !
n) && accept);
4205 char const*
const end =
s +
n;
4206 for (
char const* cur =
s; cur <
end; ++cur) {
4208 for (
char const*
a = accept; *
a; ++
a) {
4226 std::string::size_type maxsize =
4229 result.reserve(maxsize);
4232 for (
const char* c =
value; c !=
end; ++c) {
4265 std::ostringstream oss;
4266 oss <<
"\\u" << std::hex << std::uppercase << std::setfill(
'0')
4267 << std::setw(4) <<
static_cast<int>(*c);
4268 result += oss.str();
4287 : yamlCompatiblityEnabled_(
false), dropNullPlaceholders_(
false),
4288 omitEndingLineFeed_(
false) {}
4305 switch (
value.type()) {
4344 for (Value::Members::iterator
it = members.begin();
it != members.end();
4347 if (
it != members.begin())
4362 : rightMargin_(74), indentSize_(3), addChildValues_() {}
4376 switch (
value.type()) {
4407 if (members.empty())
4412 Value::Members::iterator
it = members.begin();
4420 if (++
it == members.end()) {
4440 if (isArrayMultiLine) {
4484 childValue.
size() > 0);
4490 int lineLength = 4 + (
size - 1) * 2;
4499 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
4541 std::string::const_iterator iter = comment.begin();
4542 while (iter != comment.end()) {
4544 if (*iter ==
'\n' &&
4545 (iter != comment.end() && *(iter + 1) ==
'/'))
4575 : document_(
NULL), rightMargin_(74), indentation_(indentation),
4576 addChildValues_() {}
4593 switch (
value.type()) {
4624 if (members.empty())
4629 Value::Members::iterator
it = members.begin();
4637 if (++
it == members.end()) {
4657 if (isArrayMultiLine) {
4703 childValue.
size() > 0);
4709 int lineLength = 4 + (
size - 1) * 2;
4718 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
4757 std::string::const_iterator iter = comment.begin();
4758 while (iter != comment.end()) {
4760 if (*iter ==
'\n' &&
4761 (iter != comment.end() && *(iter + 1) ==
'/'))
4807 bool useSpecialFloats,
4844 bool useSpecialFloats,
4847 , indentation_(indentation)
4849 , colonSymbol_(colonSymbol)
4850 , nullSymbol_(nullSymbol)
4851 , endingLineFeedSymbol_(endingLineFeedSymbol)
4852 , addChildValues_(
false)
4854 , useSpecialFloats_(useSpecialFloats)
4874 switch (
value.type()) {
4905 if (members.empty())
4910 Value::Members::iterator
it = members.begin();
4918 if (++
it == members.end()) {
4986 childValue.
size() > 0);
4992 int lineLength = 4 + (
size - 1) * 2;
5001 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
5045 std::string::const_iterator iter = comment.begin();
5046 while (iter != comment.end()) {
5048 if (*iter ==
'\n' &&
5049 (iter != comment.end() && *(iter + 1) ==
'/'))
5089 setDefaults(&settings_);
5095 std::string indentation = settings_[
"indentation"].asString();
5096 std::string cs_str = settings_[
"commentStyle"].asString();
5097 bool eyc = settings_[
"enableYAMLCompatibility"].asBool();
5098 bool dnp = settings_[
"dropNullPlaceholders"].asBool();
5099 bool usf = settings_[
"useSpecialFloats"].asBool();
5100 unsigned int pre = settings_[
"precision"].asUInt();
5102 if (cs_str ==
"All") {
5104 }
else if (cs_str ==
"None") {
5112 }
else if (indentation.empty()) {
5119 if (pre > 17) pre = 17;
5123 colonSymbol, nullSymbol, endingLineFeedSymbol, usf, pre);
5127 valid_keys->clear();
5128 valid_keys->insert(
"indentation");
5129 valid_keys->insert(
"commentStyle");
5130 valid_keys->insert(
"enableYAMLCompatibility");
5131 valid_keys->insert(
"dropNullPlaceholders");
5132 valid_keys->insert(
"useSpecialFloats");
5133 valid_keys->insert(
"precision");
5138 if (!invalid) invalid = &my_invalid;
5140 std::set<std::string> valid_keys;
5143 size_t n = keys.size();
5144 for (
size_t i = 0;
i <
n; ++
i) {
5146 if (valid_keys.find(
key) == valid_keys.end()) {
5147 inv[
key] = settings_[
key];
5150 return 0u == inv.
size();
5154 return settings_[
key];
5160 (*settings)[
"commentStyle"] =
"All";
5161 (*settings)[
"indentation"] =
"\t";
5162 (*settings)[
"enableYAMLCompatibility"] =
false;
5163 (*settings)[
"dropNullPlaceholders"] =
false;
5164 (*settings)[
"useSpecialFloats"] =
false;
5165 (*settings)[
"precision"] = 17;
5170 std::ostringstream sout;
5172 writer->write(
root, &sout);
5179 writer->write(
root, &sout);
bool hasCommentForValue(const Value &value)
Build a CharReader implementation.
bool recoverFromError(TokenType skipUntilToken)
#define JSON_ASSERT_MESSAGE(condition, message)
WEPOLL_INTERNAL int init(void)
unsigned long long int UInt64
bool readObject(Token &token)
char const * data() const
static std::string valueToQuotedStringN(const char *value, unsigned length)
Build a StreamWriter implementation.
Json::LargestUInt LargestUInt
GLuint const GLchar * name
Iterator for object and array value.
bool isValidIndex(ArrayIndex index) const
Return true if index < size().
bool addErrorAndRecover(const std::string &message, Token &token, TokenType skipUntilToken)
bool readStringSingleQuote()
ArrayIndex size() const
Number of values in array or object.
bool decodeString(Token &token)
void dropNullPlaceholders()
Drop the "null" string from the writer's output for nullValues. Strictly speaking,...
std::auto_ptr< CharReader > CharReaderPtr
std::string JSON_API writeString(StreamWriter::Factory const &factory, Value const &root)
Write into stringstream, then return string, for convenience. A StreamWriter will be created from the...
void copy(const SelfType &other)
const bool collectComments_
void resize(ArrayIndex size)
OurCharReader(bool collectComments, OurFeatures const &features)
std::vector< std::string > ChildValues
bool validate(Json::Value *invalid) const
std::stack< Value * > Nodes
void writeCommentBeforeValue(const Value &root)
std::string asString() const
Embedded zeroes are possible.
void setOffsetLimit(size_t limit)
std::vector< StructuredError > getStructuredErrors() const
Returns a vector of structured erros encounted while parsing.
RuntimeError(std::string const &msg)
CZString(ArrayIndex index)
bool readCppStyleComment()
bool allowDroppedNullPlaceholders_
true if dropped null placeholders are allowed. Default: false.
void skipCommentTokens(Token &token)
int compare(const Value &other) const
#define JSON_FAIL_MESSAGE(message)
Exception(std::string const &msg)
GLenum GLuint GLenum GLsizei length
std::string getFormattedErrorMessages() const
Returns a user friendly string that list errors in the parsed document.
@ arrayValue
array value (ordered list)
bool decodeDouble(Token &token)
LargestUInt asLargestUInt() const
StyledStreamWriter(std::string indentation="\t")
static bool escape(upb_json_parser *p, const char *ptr)
std::map< CZString, Value > ObjectValues
void writeCommentAfterValueOnSameLine(const Value &root)
SelfType & operator=(const ValueIteratorBase &other)
static Features strictMode()
A configuration that is strictly compatible with the JSON specification.
static bool hasCommentForValue(const Value &value)
void pushValue(std::string const &value)
bool decodeString(Token &token)
const typedef Char * Location
bool isMultineArray(const Value &value)
static void setDefaults(Json::Value *settings)
bool operator<(const Value &other) const
Compare payload only, not comments etc.
bool readArray(Token &token)
Value const * find(char const *begin, char const *end) const
std::deque< ErrorInfo > Errors
ValueConstIterator const_iterator
bool hasComment(CommentPlacement placement) const
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
const Value & resolve(const Value &root) const
Value & append(const Value &value)
Append value to array at the end.
bool dropNullPlaceholders_
static const int stackLimit_g
@ numberOfCommentPlacement
root value)
static void getValidReaderKeys(std::set< std::string > *valid_keys)
static bool containsControlCharacter0(const char *str, unsigned len)
GLsizei const GLchar *const * string
bool decodeNumber(Token &token)
void writeValue(const Value &value)
void swap(Value &other)
Swap everything.
Value & make(Value &root) const
bool allowDroppedNullPlaceholders_
UInt index() const
Return the index of the referenced Value, or -1 if it is not an arrayValue.
bool allowComments_
true if comments are allowed. Default: true.
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
bool readNumber(bool checkInf)
#define T(upbtypeconst, upbtype, ctype, default_value)
virtual StreamWriter * newStreamWriter() const =0
Allocate a CharReader via operator new().
bool isEqual(const SelfType &other) const
void skipCommentTokens(Token &token)
const unsigned char & kNullRef
void writeWithIndent(const std::string &value)
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
std::string write(const Value &root) override
Serialize a Value in JSON format.
Value & operator=(Value other)
size_t getOffsetLimit() const
static bool IsIntegral(double d)
#define JSON_ASSERT(condition)
void pushValue(const std::string &value)
void omitEndingLineFeed()
BuiltStyledStreamWriter(std::string const &indentation, CommentStyle::Enum cs, std::string const &colonSymbol, std::string const &nullSymbol, std::string const &endingLineFeedSymbol, bool useSpecialFloats, unsigned int precision)
std::string indentString_
~StreamWriterBuilder() override
GLboolean GLboolean GLboolean b
static const Value & nullRef
bool pushError(const Value &value, const std::string &message)
void writeArrayValue(const Value &value)
Value::ObjectValues::iterator current_
void writeCommentBeforeValue(const Value &root)
void addComment(Location begin, Location end, CommentPlacement placement)
JSON_API std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
static size_t begin(const upb_table *t)
static bool containsNewLine(Reader::Location begin, Reader::Location end)
static void uintToString(LargestUInt value, char *¤t)
static void strictMode(Json::Value *settings)
bool readObject(Token &token)
int snprintf(char *str, size_t size, const char *format,...)
void writeArrayValue(const Value &value)
@ uintValue
unsigned integer value
LogicError(std::string const &msg)
static const Value & null
We regret this reference to a global instance; prefer the simpler Value().
Value get(ArrayIndex index, const Value &defaultValue) const
void write(std::ostream &out, const Value &root)
Serialize a Value in JSON format.
JSON (JavaScript Object Notation).
static bool containsControlCharacter(const char *str)
def root(location=None, arch=None, version=None, threading=None, exceptions=None, revision=None, log=EmptyLogger())
static char * duplicateAndPrefixStringValue(const char *value, unsigned int length)
bool operator==(const Value &other) const
GLsizei const GLchar ** path
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)]
bool allowNumericKeys_
true if numeric object key are allowed. Default: false.
bool decodeNumber(Token &token)
void enableYAMLCompatibility()
void invalidPath(const std::string &path, int location)
@ objectValue
object value (collection of name/value pairs).
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
GLint GLint GLsizei GLint GLenum format
void getLocationLineAndColumn(Location location, int &line, int &column) const
An error tagged with where in the JSON text it was encountered.
Writes a Value in JSON format in a human friendly way.
union Json::Value::ValueHolder value_
bool isMultineArray(Value const &value)
bool readToken(Token &token)
~CharReaderBuilder() override
bool match(Location pattern, int patternLength)
void setComment(const char *comment, CommentPlacement placement)
virtual CharReader * newCharReader() const =0
Allocate a CharReader via operator new().
const iterator for object and array value.
StreamWriter * newStreamWriter() const override
std::string commentsBefore_
Value & resolveReference(const char *key)
char const * memberName() const
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
bool decodeUnicodeEscapeSequence(Token &token, Location ¤t, Location end, unsigned int &unicode)
bool hasCommentForValue(const Value &value)
void setOffsetStart(size_t start)
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
const_iterator end() const
bool validate(Json::Value *invalid) const
void pushValue(const std::string &value)
std::string commentsBefore_
bool isMultineArray(const Value &value)
static void releaseStringValue(char *value)
base class for Value iterators.
bool decodeUnicodeCodePoint(Token &token, Location ¤t, Location end, unsigned int &unicode)
GLint GLenum GLboolean normalized
bool good() const
Return whether there are any errors.
bool parse(const char *beginDoc, const char *endDoc, Value &root, bool collectComments=true)
static bool isControlCharacter(char ch)
Returns true if ch is a control character (in range [1,31]).
std::string JSON_API valueToString(Int value)
void writeValue(Value const &value)
void getLocationLineAndColumn(Location location, int &line, int &column) const
static void getValidWriterKeys(std::set< std::string > *valid_keys)
bool decodeUnicodeEscapeSequence(Token &token, Location ¤t, Location end, unsigned int &unicode)
@ commentBefore
a comment placed on the line before a value
bool operator<(CZString const &other) const
std::vector< StructuredError > getStructuredErrors() const
static char const * strnpbrk(char const *s, char const *accept, size_t n)
bool JSON_API parseFromStream(CharReader::Factory const &, std::istream &, Value *root, std::string *errs)
std::vector< const PathArgument * > InArgs
GLenum GLint GLint * precision
@ stringValue
UTF-8 string value.
size_t getOffsetStart() const
ValueType
Type of the value held by a Value object.
Value & operator[](std::string key)
void swap(CZString &other)
const SETUP_TEARDOWN_TESTCONTEXT char * key
bool addErrorAndRecover(const std::string &message, Token &token, TokenType skipUntilToken)
bool decodeUnicodeCodePoint(Token &token, Location ¤t, Location end, unsigned int &unicode)
std::string write(const Value &root) override
char const * what() const override
bool operator==(CZString const &other) const
bool pushError(const Value &value, const std::string &message)
Add a semantic error message.
void operator=(OurReader const &)
CharReader * newCharReader() const override
Allocate a CharReader via operator new().
void swapPayload(Value &other)
Swap values but leave comments and source offsets in place.
bool operator>=(const Value &other) const
bool getString(char const **begin, char const **end) const
void writeWithIndent(std::string const &value)
Members getMemberNames() const
Return a list of the member names.
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
std::string getFormattedErrorMessages() const
const typedef Char * Location
const char * asCString() const
Embedded zeroes could cause you trouble!
void writeCommentAfterValueOnSameLine(const Value &root)
bool isMember(const char *key) const
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
bool parse(char const *beginDoc, char const *endDoc, Value *root, std::string *errs) override
Read a Value from a JSON document. The document must be a UTF-8 encoded string containing the documen...
difference_type computeDistance(const SelfType &other) const
void writeWithIndent(const std::string &value)
bool addError(const std::string &message, Token &token, Location extra=0)
Value & operator[](std::string key)
SelfType & operator=(const SelfType &other)
Experimental and untested: represents an element of the "path" to access a node.
void makePath(const std::string &path, const InArgs &in)
static std::string codePointToUTF8(unsigned int cp)
Converts a unicode code-point to UTF-8.
JSON_API std::istream & operator>>(std::istream &, Value &)
Read from 'sin' into 'root'.
std::string indentString_
CZString & operator=(CZString other)
zend_class_entry * value_type
bool operator!() const
Return isNull()
A simple abstract factory.
void addPathInArg(const std::string &path, const InArgs &in, InArgs::const_iterator &itInArg, PathArgument::Kind kind)
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
Lightweight wrapper to tag static string.
static void decodePrefixedString(bool isPrefixed, char const *prefixed, unsigned *length, char const **value)
void writeArrayValue(Value const &value)
Reader()
Constructs a Reader allowing all features for parsing.
@ intValue
signed integer value
std::string getComment(CommentPlacement placement) const
Include delimiters and embedded newlines.
static Features all()
A configuration that allows all features and assumes all strings are UTF-8.
#define JSON_ASSERT_UNREACHABLE
static bool InRange(double d, T min, U max)
bool readToken(Token &token)
Json::ArrayIndex ArrayIndex
std::string endingLineFeedSymbol_
static char * duplicateStringValue(const char *value, size_t length)
Path(const std::string &path, const PathArgument &a1=PathArgument(), const PathArgument &a2=PathArgument(), const PathArgument &a3=PathArgument(), const PathArgument &a4=PathArgument(), const PathArgument &a5=PathArgument())
std::string getFormatedErrorMessages() const
Returns a user friendly string that list errors in the parsed document.
bool empty() const
Return true if empty array, empty object, or null; otherwise, false.
char UIntToStringBuffer[uintToStringBufferSize]
void writeValue(const Value &value)
LargestInt asLargestInt() const
std::string JSON_API valueToQuotedString(const char *value)
const_iterator begin() const
int write(Value const &root, std::ostream *sout) override
bool recoverFromError(TokenType skipUntilToken)
bool isConvertibleTo(ValueType other) const
void writeCommentBeforeValue(Value const &root)
std::vector< std::string > Members
Value removeMember(const char *key)
Remove and return the named member.
Features()
Initialize the configuration like JsonConfig::allFeatures;.
bool readArray(Token &token)
static void fixNumericLocale(char *begin, char *end)
static const Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
bool readCppStyleComment()
GLsizei const GLfloat * value
bool removeIndex(ArrayIndex i, Value *removed)
Remove the indexed array element.
bool decodeDouble(Token &token)
void throwRuntimeError(std::string const &msg)
used internally
Value & operator[](ArrayIndex index)
const OurFeatures features_
bool addError(const std::string &message, Token &token, Location extra=0)
void addComment(Location begin, Location end, CommentPlacement placement)
std::auto_ptr< StreamWriter > StreamWriterPtr
OurReader(OurFeatures const &features)
static std::string normalizeEOL(Reader::Location begin, Reader::Location end)
void writeValue(const Value &value)
void initBasic(ValueType type, bool allocated=false)
bool isStaticString() const
GLboolean GLboolean GLboolean GLboolean a
std::string indentString_
bool operator<=(const Value &other) const
static int32_t skip(upb_pbdecoder *d, size_t bytes)
std::string toStyledString() const
@ commentAfterOnSameLine
a comment just after a value on the same line
Json::LargestInt LargestInt
GLenum GLuint GLenum GLsizei const GLchar * message
void writeCommentAfterValueOnSameLine(Value const &root)
bool yamlCompatiblityEnabled_
static void setDefaults(Json::Value *settings)
bool operator>(const Value &other) const
Value(ValueType type=nullValue)
Create a default Value of the given type.
void throwLogicError(std::string const &msg)
used internally
bool match(Location pattern, int patternLength)
bool operator!=(const Value &other) const
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55