mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-26 18:51:04 +08:00
Builder::operator[] plus tests
This commit is contained in:
parent
42d7e59fe0
commit
c312dd5ef7
@ -285,7 +285,7 @@ Usage:
|
||||
\code
|
||||
using namespace Json;
|
||||
CharReaderBuilder builder;
|
||||
builder.settings_["collectComments"] = false;
|
||||
builder["collectComments"] = false;
|
||||
Value value;
|
||||
std::string errs;
|
||||
bool ok = parseFromStream(builder, std::cin, &value, &errs);
|
||||
@ -337,6 +337,11 @@ public:
|
||||
* otherwise, indicate bad settings via 'invalid'.
|
||||
*/
|
||||
bool validate(Json::Value* invalid) const;
|
||||
|
||||
/** A simple way to update a specific setting.
|
||||
*/
|
||||
Value& operator[](std::string key);
|
||||
|
||||
/** Called by ctor, but you can use this to reset settings_.
|
||||
* \pre 'settings' != NULL (but Json::null is fine)
|
||||
* \remark Defaults:
|
||||
|
@ -119,6 +119,10 @@ public:
|
||||
* otherwise, indicate bad settings via 'invalid'.
|
||||
*/
|
||||
bool validate(Json::Value* invalid) const;
|
||||
/** A simple way to update a specific setting.
|
||||
*/
|
||||
Value& operator[](std::string key);
|
||||
|
||||
/** Called by ctor, but you can use this to reset settings_.
|
||||
* \pre 'settings' != NULL (but Json::null is fine)
|
||||
* \remark Defaults:
|
||||
|
@ -1927,6 +1927,10 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const
|
||||
}
|
||||
return 0u == inv.size();
|
||||
}
|
||||
Value& CharReaderBuilder::operator[](std::string key)
|
||||
{
|
||||
return settings_[key];
|
||||
}
|
||||
// static
|
||||
void CharReaderBuilder::strictMode(Json::Value* settings)
|
||||
{
|
||||
|
@ -1122,6 +1122,10 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const
|
||||
}
|
||||
return 0u == inv.size();
|
||||
}
|
||||
Value& StreamWriterBuilder::operator[](std::string key)
|
||||
{
|
||||
return settings_[key];
|
||||
}
|
||||
// static
|
||||
void StreamWriterBuilder::setDefaults(Json::Value* settings)
|
||||
{
|
||||
|
@ -2182,7 +2182,7 @@ JSONTEST_FIXTURE(BuilderTest, settings) {
|
||||
Json::CharReaderBuilder rb;
|
||||
JSONTEST_ASSERT_EQUAL(false, rb.settings_.isMember("foo"));
|
||||
JSONTEST_ASSERT_EQUAL(true, rb.validate(&errs));
|
||||
rb.settings_["foo"] = "bar";
|
||||
rb["foo"] = "bar";
|
||||
JSONTEST_ASSERT_EQUAL(true, rb.settings_.isMember("foo"));
|
||||
JSONTEST_ASSERT_EQUAL(false, rb.validate(&errs));
|
||||
}
|
||||
@ -2191,7 +2191,7 @@ JSONTEST_FIXTURE(BuilderTest, settings) {
|
||||
Json::StreamWriterBuilder wb;
|
||||
JSONTEST_ASSERT_EQUAL(false, wb.settings_.isMember("foo"));
|
||||
JSONTEST_ASSERT_EQUAL(true, wb.validate(&errs));
|
||||
wb.settings_["foo"] = "bar";
|
||||
wb["foo"] = "bar";
|
||||
JSONTEST_ASSERT_EQUAL(true, wb.settings_.isMember("foo"));
|
||||
JSONTEST_ASSERT_EQUAL(false, wb.validate(&errs));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user