mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-15 07:14:45 +02:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f9db82af17 | ||
![]() |
ae71879549 | ||
![]() |
7b3683ccd1 | ||
![]() |
58499031a4 | ||
![]() |
2c8c1ac0ec | ||
![]() |
c58e93b014 | ||
![]() |
eed193e151 | ||
![]() |
4382a7b585 | ||
![]() |
30d923f155 | ||
![]() |
2f4e40bc95 | ||
![]() |
505e086ebc | ||
![]() |
c6582415d8 | ||
![]() |
0ee7e2426f | ||
![]() |
1522e4dfb1 | ||
![]() |
09b8670536 |
@@ -59,7 +59,7 @@ def amalgamate_source(source_top_dir=None,
|
|||||||
print("Amalgating header...")
|
print("Amalgating header...")
|
||||||
header = AmalgamationFile(source_top_dir)
|
header = AmalgamationFile(source_top_dir)
|
||||||
header.add_text("/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).")
|
header.add_text("/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).")
|
||||||
header.add_text("/// It is intented to be used with #include <%s>" % header_include_path)
|
header.add_text('/// It is intended to be used with #include "%s"' % header_include_path)
|
||||||
header.add_file("LICENSE", wrap_in_comment=True)
|
header.add_file("LICENSE", wrap_in_comment=True)
|
||||||
header.add_text("#ifndef JSON_AMALGATED_H_INCLUDED")
|
header.add_text("#ifndef JSON_AMALGATED_H_INCLUDED")
|
||||||
header.add_text("# define JSON_AMALGATED_H_INCLUDED")
|
header.add_text("# define JSON_AMALGATED_H_INCLUDED")
|
||||||
@@ -85,7 +85,7 @@ def amalgamate_source(source_top_dir=None,
|
|||||||
print("Amalgating forward header...")
|
print("Amalgating forward header...")
|
||||||
header = AmalgamationFile(source_top_dir)
|
header = AmalgamationFile(source_top_dir)
|
||||||
header.add_text("/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/).")
|
header.add_text("/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/).")
|
||||||
header.add_text("/// It is intented to be used with #include <%s>" % forward_header_include_path)
|
header.add_text('/// It is intended to be used with #include "%s"' % forward_header_include_path)
|
||||||
header.add_text("/// This header provides forward declaration for all JsonCpp types.")
|
header.add_text("/// This header provides forward declaration for all JsonCpp types.")
|
||||||
header.add_file("LICENSE", wrap_in_comment=True)
|
header.add_file("LICENSE", wrap_in_comment=True)
|
||||||
header.add_text("#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED")
|
header.add_text("#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED")
|
||||||
@@ -105,10 +105,15 @@ def amalgamate_source(source_top_dir=None,
|
|||||||
print("Amalgating source...")
|
print("Amalgating source...")
|
||||||
source = AmalgamationFile(source_top_dir)
|
source = AmalgamationFile(source_top_dir)
|
||||||
source.add_text("/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/).")
|
source.add_text("/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/).")
|
||||||
source.add_text("/// It is intented to be used with #include <%s>" % header_include_path)
|
source.add_text('/// It is intended to be used with #include "%s"' % header_include_path)
|
||||||
source.add_file("LICENSE", wrap_in_comment=True)
|
source.add_file("LICENSE", wrap_in_comment=True)
|
||||||
source.add_text("")
|
source.add_text("")
|
||||||
source.add_text("#include <%s>" % header_include_path)
|
source.add_text('#include "%s"' % header_include_path)
|
||||||
|
source.add_text("""
|
||||||
|
#ifndef JSON_IS_AMALGAMATION
|
||||||
|
#error "Compile with -I PATH_TO_JSON_DIRECTORY"
|
||||||
|
#endif
|
||||||
|
""")
|
||||||
source.add_text("")
|
source.add_text("")
|
||||||
lib_json = "src/lib_json"
|
lib_json = "src/lib_json"
|
||||||
source.add_file(os.path.join(lib_json, "json_tool.h"))
|
source.add_file(os.path.join(lib_json, "json_tool.h"))
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
#if JSON_USE_EXCEPTION
|
#if JSON_USE_EXCEPTION
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#define JSON_ASSERT(condition) \
|
#define JSON_ASSERT(condition) \
|
||||||
assert(condition); // @todo <= change this into an exception throw
|
if (!(condition)) {throw std::runtime_error( "assert json failed" );} // @todo <= add detail about condition in exception
|
||||||
#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::runtime_error(oss.str());}while(0)
|
#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::runtime_error(oss.str());}while(0)
|
||||||
//#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message)
|
//#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message)
|
||||||
#else // JSON_USE_EXCEPTION
|
#else // JSON_USE_EXCEPTION
|
||||||
|
@@ -4,10 +4,10 @@
|
|||||||
#ifndef JSON_VERSION_H_INCLUDED
|
#ifndef JSON_VERSION_H_INCLUDED
|
||||||
# define JSON_VERSION_H_INCLUDED
|
# define JSON_VERSION_H_INCLUDED
|
||||||
|
|
||||||
# define JSONCPP_VERSION_STRING "1.4.2"
|
# define JSONCPP_VERSION_STRING "1.4.4"
|
||||||
# define JSONCPP_VERSION_MAJOR 1
|
# define JSONCPP_VERSION_MAJOR 1
|
||||||
# define JSONCPP_VERSION_MINOR 4
|
# define JSONCPP_VERSION_MINOR 4
|
||||||
# define JSONCPP_VERSION_PATCH 2
|
# define JSONCPP_VERSION_PATCH 4
|
||||||
# define JSONCPP_VERSION_QUALIFIER
|
# define JSONCPP_VERSION_QUALIFIER
|
||||||
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
|
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
|
||||||
|
|
||||||
|
@@ -200,6 +200,8 @@ bool Reader::readValue() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case tokenArraySeparator:
|
case tokenArraySeparator:
|
||||||
|
case tokenObjectEnd:
|
||||||
|
case tokenArrayEnd:
|
||||||
if (features_.allowDroppedNullPlaceholders_) {
|
if (features_.allowDroppedNullPlaceholders_) {
|
||||||
// "Un-read" the current token and mark the current value as a null
|
// "Un-read" the current token and mark the current value as a null
|
||||||
// token.
|
// token.
|
||||||
@@ -209,8 +211,7 @@ bool Reader::readValue() {
|
|||||||
currentValue().setOffsetStart(current_ - begin_ - 1);
|
currentValue().setOffsetStart(current_ - begin_ - 1);
|
||||||
currentValue().setOffsetLimit(current_ - begin_);
|
currentValue().setOffsetLimit(current_ - begin_);
|
||||||
break;
|
break;
|
||||||
}
|
} // Else, fall through...
|
||||||
// Else, fall through...
|
|
||||||
default:
|
default:
|
||||||
currentValue().setOffsetStart(token.start_ - begin_);
|
currentValue().setOffsetStart(token.start_ - begin_);
|
||||||
currentValue().setOffsetLimit(token.end_ - begin_);
|
currentValue().setOffsetLimit(token.end_ - begin_);
|
||||||
@@ -1160,6 +1161,8 @@ bool OurReader::readValue() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case tokenArraySeparator:
|
case tokenArraySeparator:
|
||||||
|
case tokenObjectEnd:
|
||||||
|
case tokenArrayEnd:
|
||||||
if (features_.allowDroppedNullPlaceholders_) {
|
if (features_.allowDroppedNullPlaceholders_) {
|
||||||
// "Un-read" the current token and mark the current value as a null
|
// "Un-read" the current token and mark the current value as a null
|
||||||
// token.
|
// token.
|
||||||
@@ -1169,8 +1172,7 @@ bool OurReader::readValue() {
|
|||||||
currentValue().setOffsetStart(current_ - begin_ - 1);
|
currentValue().setOffsetStart(current_ - begin_ - 1);
|
||||||
currentValue().setOffsetLimit(current_ - begin_);
|
currentValue().setOffsetLimit(current_ - begin_);
|
||||||
break;
|
break;
|
||||||
}
|
} // else, fall through ...
|
||||||
// Else, fall through...
|
|
||||||
default:
|
default:
|
||||||
currentValue().setOffsetStart(token.start_ - begin_);
|
currentValue().setOffsetStart(token.start_ - begin_);
|
||||||
currentValue().setOffsetLimit(token.end_ - begin_);
|
currentValue().setOffsetLimit(token.end_ - begin_);
|
||||||
|
@@ -1862,6 +1862,158 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, commentAfterBool) {
|
|||||||
delete reader;
|
delete reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CharReaderAllowDropNullTest : JsonTest::TestCase {};
|
||||||
|
|
||||||
|
JSONTEST_FIXTURE(CharReaderAllowDropNullTest, issue178) {
|
||||||
|
Json::CharReaderBuilder b;
|
||||||
|
b.settings_["allowDroppedNullPlaceholders"] = true;
|
||||||
|
Json::Value root;
|
||||||
|
std::string errs;
|
||||||
|
Json::CharReader* reader(b.newCharReader());
|
||||||
|
{
|
||||||
|
char const doc[] = "{\"a\":,\"b\":true}";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(2u, root.size());
|
||||||
|
JSONTEST_ASSERT_EQUAL(Json::nullValue, root.get("a", true));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "{\"a\":}";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(1u, root.size());
|
||||||
|
JSONTEST_ASSERT_EQUAL(Json::nullValue, root.get("a", true));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT(errs == "");
|
||||||
|
JSONTEST_ASSERT_EQUAL(0u, root.size());
|
||||||
|
JSONTEST_ASSERT_EQUAL(Json::arrayValue, root);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[null]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT(errs == "");
|
||||||
|
JSONTEST_ASSERT_EQUAL(1u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(2u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,,,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(4u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[null,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(2u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,null]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT(errs == "");
|
||||||
|
JSONTEST_ASSERT_EQUAL(2u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(3u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[null,,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(3u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,null,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(3u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,,null]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT(errs == "");
|
||||||
|
JSONTEST_ASSERT_EQUAL(3u, root.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[[],,,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(4u, root.size());
|
||||||
|
JSONTEST_ASSERT_EQUAL(Json::arrayValue, root[0u]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,[],,]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL(4u, root.size());
|
||||||
|
JSONTEST_ASSERT_EQUAL(Json::arrayValue, root[1u]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char const doc[] = "[,,,[]]";
|
||||||
|
bool ok = reader->parse(
|
||||||
|
doc, doc + std::strlen(doc),
|
||||||
|
&root, &errs);
|
||||||
|
JSONTEST_ASSERT(ok);
|
||||||
|
JSONTEST_ASSERT(errs == "");
|
||||||
|
JSONTEST_ASSERT_EQUAL(4u, root.size());
|
||||||
|
JSONTEST_ASSERT_EQUAL(Json::arrayValue, root[3u]);
|
||||||
|
}
|
||||||
|
delete reader;
|
||||||
|
}
|
||||||
|
|
||||||
struct IteratorTest : JsonTest::TestCase {};
|
struct IteratorTest : JsonTest::TestCase {};
|
||||||
|
|
||||||
JSONTEST_FIXTURE(IteratorTest, distance) {
|
JSONTEST_FIXTURE(IteratorTest, distance) {
|
||||||
@@ -1925,6 +2077,8 @@ int main(int argc, const char* argv[]) {
|
|||||||
JSONTEST_REGISTER_FIXTURE(runner, CharReaderFailIfExtraTest, commentAfterArray);
|
JSONTEST_REGISTER_FIXTURE(runner, CharReaderFailIfExtraTest, commentAfterArray);
|
||||||
JSONTEST_REGISTER_FIXTURE(runner, CharReaderFailIfExtraTest, commentAfterBool);
|
JSONTEST_REGISTER_FIXTURE(runner, CharReaderFailIfExtraTest, commentAfterBool);
|
||||||
|
|
||||||
|
JSONTEST_REGISTER_FIXTURE(runner, CharReaderAllowDropNullTest, issue178);
|
||||||
|
|
||||||
JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, distance);
|
JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, distance);
|
||||||
|
|
||||||
return runner.runCommandLine(argc, argv);
|
return runner.runCommandLine(argc, argv);
|
||||||
|
Reference in New Issue
Block a user