- added Features class that describes allowed extension for Reader, to allow for strict configuration
- added tests from json.org jsonchecker and modified jsontestrunner to use strict parsing mode when executing them
diff --git a/include/json/features.h b/include/json/features.h
new file mode 100644
index 0000000..f1404f6
--- /dev/null
+++ b/include/json/features.h
@@ -0,0 +1,42 @@
+#ifndef CPPTL_JSON_FEATURES_H_INCLUDED
+# define CPPTL_JSON_FEATURES_H_INCLUDED
+
+# include "forwards.h"
+
+namespace Json {
+
+ /** \brief Configuration passed to reader and writer.
+ * This configuration object can be used to force the Reader or Writer
+ * to behave in a standard conforming way.
+ */
+ class JSON_API Features
+ {
+ public:
+ /** \brief A configuration that allows all features and assumes all strings are UTF-8.
+ * - C & C++ comments are allowed
+ * - Root object can be any JSON value
+ * - Assumes Value strings are encoded in UTF-8
+ */
+ static Features all();
+
+ /** \brief A configuration that is strictly compatible with the JSON specification.
+ * - Comments are forbidden.
+ * - Root object must be either an array or an object value.
+ * - Assumes Value strings are encoded in UTF-8
+ */
+ static Features strictMode();
+
+ /** \brief Initialize the configuration like JsonConfig::allFeatures;
+ */
+ Features();
+
+ /// \c true if comments are allowed. Default: \c true.
+ bool allowComments_;
+
+ /// \c true if root must be either an array or an object value. Default: \c false.
+ bool strictRoot_;
+ };
+
+} // namespace Json
+
+#endif // CPPTL_JSON_FEATURES_H_INCLUDED
diff --git a/include/json/forwards.h b/include/json/forwards.h
index 3372a55..ee76071 100644
--- a/include/json/forwards.h
+++ b/include/json/forwards.h
@@ -9,6 +9,9 @@
class Reader;
class StyledWriter;
+ // features.h
+ class Features;
+
// value.h
class StaticString;
class Path;
diff --git a/include/json/json.h b/include/json/json.h
index a539740..c71ed65 100644
--- a/include/json/json.h
+++ b/include/json/json.h
@@ -5,5 +5,6 @@
# include "value.h"
# include "reader.h"
# include "writer.h"
+# include "features.h"
#endif // JSON_JSON_H_INCLUDED
diff --git a/include/json/reader.h b/include/json/reader.h
index e113569..ee1d6a2 100644
--- a/include/json/reader.h
+++ b/include/json/reader.h
@@ -1,7 +1,7 @@
#ifndef CPPTL_JSON_READER_H_INCLUDED
# define CPPTL_JSON_READER_H_INCLUDED
-# include "forwards.h"
+# include "features.h"
# include "value.h"
# include <deque>
# include <stack>
@@ -10,11 +10,8 @@
namespace Json {
- class Value;
-
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a Value.
*
- *
*/
class JSON_API Reader
{
@@ -22,14 +19,24 @@
typedef char Char;
typedef const Char *Location;
+ /** \brief Constructs a Reader allowing all features
+ * for parsing.
+ */
Reader();
+ /** \brief Constructs a Reader allowing the specified feature set
+ * for parsing.
+ */
+ Reader( const Features &features );
+
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
* \param document UTF-8 encoded string containing the document to read.
* \param root [out] Contains the root value of the document if it was
* successfully parsed.
* \param collectComments \c true to collect comment and allow writing them back during
* serialization, \c false to discard comments.
+ * This parameter is ignored if Features::allowComments_
+ * is \c false.
* \return \c true if the document was successfully parsed, \c false if an error occurred.
*/
bool parse( const std::string &document,
@@ -42,6 +49,8 @@
* successfully parsed.
* \param collectComments \c true to collect comment and allow writing them back during
* serialization, \c false to discard comments.
+ * This parameter is ignored if Features::allowComments_
+ * is \c false.
* \return \c true if the document was successfully parsed, \c false if an error occurred.
*/
bool parse( const char *beginDoc, const char *endDoc,
@@ -50,7 +59,7 @@
/// \brief Parse from input stream.
/// \see Json::operator>>(std::istream&, Json::Value&).
- bool parse( std::istream&,
+ bool parse( std::istream &is,
Value &root,
bool collectComments = true );
@@ -152,6 +161,7 @@
Location lastValueEnd_;
Value *lastValue_;
std::string commentsBefore_;
+ Features features_;
bool collectComments_;
};