From a71fcfa85ecf959329a027901f4fad43c592f462 Mon Sep 17 00:00:00 2001 From: Rich E Date: Sun, 25 Jan 2015 04:48:03 +0100 Subject: [PATCH] add ParseOptions::allowComments(), default = true --- include/cinder/Json.h | 11 ++++++----- src/cinder/Json.cpp | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/cinder/Json.h b/include/cinder/Json.h index dc855c387a..abe875a700 100755 --- a/include/cinder/Json.h +++ b/include/cinder/Json.h @@ -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. diff --git a/src/cinder/Json.cpp b/src/cinder/Json.cpp index 88c7840020..97187ea865 100755 --- a/src/cinder/Json.cpp +++ b/src/cinder/Json.cpp @@ -39,7 +39,7 @@ using namespace std; namespace cinder { JsonTree::ParseOptions::ParseOptions() -: mIgnoreErrors( false ) + : mIgnoreErrors( false ), mAllowComments( true ) { } @@ -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 ) { @@ -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 {