Skip to content

Commit

Permalink
add ParseOptions::allowComments(), default = true
Browse files Browse the repository at this point in the history
  • Loading branch information
richardeakin committed Jan 25, 2015
1 parent 265ae64 commit a71fcfa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
11 changes: 6 additions & 5 deletions include/cinder/Json.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ class JsonTree {
ParseOptions& ignoreErrors( bool ignore = true );
//! Returns whether JSON parse errors are ignored.
bool getIgnoreErrors() const;

//! Sets if comments are allowed. Default \c true.
ParseOptions& allowComments( bool allow = true );
//! Returns whether comments are allowed or not.
bool getAllowComments() const;

private:
//! \cond
bool mIgnoreErrors;
//! \endcond

bool mIgnoreErrors, mAllowComments;
};

//! Options for JSON writing. Passed to the \c write method.
Expand Down
15 changes: 13 additions & 2 deletions src/cinder/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace std;
namespace cinder {

JsonTree::ParseOptions::ParseOptions()
: mIgnoreErrors( false )
: mIgnoreErrors( false ), mAllowComments( true )
{
}

Expand All @@ -54,6 +54,17 @@ bool JsonTree::ParseOptions::getIgnoreErrors() const
return mIgnoreErrors;
}

JsonTree::ParseOptions& JsonTree::ParseOptions::allowComments( bool allow )
{
mAllowComments = allow;
return *this;
}

bool JsonTree::ParseOptions::getAllowComments() const
{
return mAllowComments;
}

JsonTree::WriteOptions::WriteOptions()
: mCreateDocument( false ), mIndented( true )
{
Expand Down Expand Up @@ -267,8 +278,8 @@ void JsonTree::init( const string &key, const Json::Value &value, bool setType,
Json::Value JsonTree::deserializeNative( const string &jsonString, ParseOptions parseOptions )
{
Json::Features features;
features.allowComments_ = false;
features.strictRoot_ = !parseOptions.getIgnoreErrors();
features.allowComments_ = parseOptions.getAllowComments();
Json::Reader reader( features );
Json::Value value;
try {
Expand Down

0 comments on commit a71fcfa

Please sign in to comment.