diff --git a/doc/jsoncpp.dox b/doc/jsoncpp.dox index ed18809..563590c 100644 --- a/doc/jsoncpp.dox +++ b/doc/jsoncpp.dox @@ -103,6 +103,22 @@ std::string errs; bool ok = Json::parseFromStream(rbuilder, std::cin, &root, &errs); \endcode +Yes, compile-time configuration-checking would be helpful, +but `Json::Value` lets you +write and read the builder configuration, which is better! In other words, +you can configure your JSON parser using JSON. + +CharReaders and StreamWriters are not thread-safe, but they are re-usable. +\code +Json::CharReaderBuilder rbuilder; +cfg >> rbuilder.settings_; +std::unique_ptr const reader(rbuilder.newCharReader()); +reader->parse(start, stop, &value1, &errs); +// ... +reader->parse(start, stop, &value2, &errs); +// etc. +\endcode + \section _pbuild Build instructions The build instructions are located in the file README.md in the top-directory of the project. @@ -137,5 +153,7 @@ and recognized in your jurisdiction. \author Baptiste Lepilleur (originator) \version \include version +We make strong guarantees about binary-compatibility, consistent with +the Apache versioning scheme. \sa version.h */ diff --git a/include/json/reader.h b/include/json/reader.h index 2736931..eb4ef97 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -296,12 +296,14 @@ public: // Note: We use a Json::Value so that we can add data-members to this class // without a major version bump. /** Configuration of this builder. + These are case-sensitive. Available settings (case-sensitive): - "collectComments": false or true (default=true) - TODO: other features ... - But don't trust these docs. You can examine 'settings_` yourself + You can examine 'settings_` yourself to see the defaults. You can also write and read them just like any JSON Value. + \sa setDefaults(Json::Value*) */ Json::Value settings_; @@ -316,8 +318,16 @@ public: bool validate(Json::Value* invalid) const; /** Called by ctor, but you can use this to reset settings_. * \pre 'settings' != NULL (but Json::null is fine) + * \remark Defaults: + * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode */ static void setDefaults(Json::Value* settings); + /** Same as old Features::strictMode(). + * \pre 'settings' != NULL (but Json::null is fine) + * \remark Defaults: + * \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults + */ + static void strictMode(Json::Value* settings); }; /** Consume entire stream and use its begin/end. diff --git a/include/json/writer.h b/include/json/writer.h index 39f8cdc..2e074c1 100644 --- a/include/json/writer.h +++ b/include/json/writer.h @@ -121,6 +121,8 @@ public: bool validate(Json::Value* invalid) const; /** Called by ctor, but you can use this to reset settings_. * \pre 'settings' != NULL (but Json::null is fine) + * \remark Defaults: + * \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults */ static void setDefaults(Json::Value* settings); }; diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 82c0a23..4a3ffda 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -952,9 +952,25 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const return valid; } // static +void CharReaderBuilder::strictMode(Json::Value* settings) +{ +//! [CharReaderBuilderStrictMode] + (*settings)["allowComments"] = false; + (*settings)["strictRoot"] = true; + (*settings)["allowDroppedNullPlaceholders"] = false; + (*settings)["allowNumericKeys"] = false; +//! [CharReaderBuilderStrictMode] +} +// static void CharReaderBuilder::setDefaults(Json::Value* settings) { +//! [CharReaderBuilderDefaults] (*settings)["collectComments"] = true; + (*settings)["allowComments"] = true; + (*settings)["strictRoot"] = false; + (*settings)["allowDroppedNullPlaceholders"] = false; + (*settings)["allowNumericKeys"] = false; +//! [CharReaderBuilderDefaults] } ////////////////////////////////// diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index d0eadf5..bc9401b 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -1008,8 +1008,10 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const // static void StreamWriterBuilder::setDefaults(Json::Value* settings) { + //! [StreamWriterBuilderDefaults] (*settings)["commentStyle"] = "All"; (*settings)["indentation"] = "\t"; + //! [StreamWriterBuilderDefaults] } /*