mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-26 18:51:04 +08:00
revert trailing comma in old Reader (#1126)
This commit is contained in:
parent
dc180eb25e
commit
3beb37ea14
@ -23,7 +23,6 @@ public:
|
|||||||
/** \brief A configuration that allows all features and assumes all strings
|
/** \brief A configuration that allows all features and assumes all strings
|
||||||
* are UTF-8.
|
* are UTF-8.
|
||||||
* - C & C++ comments are allowed
|
* - C & C++ comments are allowed
|
||||||
* - Trailing commas in objects and arrays are allowed.
|
|
||||||
* - Root object can be any JSON value
|
* - Root object can be any JSON value
|
||||||
* - Assumes Value strings are encoded in UTF-8
|
* - Assumes Value strings are encoded in UTF-8
|
||||||
*/
|
*/
|
||||||
@ -32,7 +31,6 @@ public:
|
|||||||
/** \brief A configuration that is strictly compatible with the JSON
|
/** \brief A configuration that is strictly compatible with the JSON
|
||||||
* specification.
|
* specification.
|
||||||
* - Comments are forbidden.
|
* - Comments are forbidden.
|
||||||
* - Trailing commas in objects and arrays are forbidden.
|
|
||||||
* - Root object must be either an array or an object value.
|
* - Root object must be either an array or an object value.
|
||||||
* - Assumes Value strings are encoded in UTF-8
|
* - Assumes Value strings are encoded in UTF-8
|
||||||
*/
|
*/
|
||||||
@ -45,10 +43,6 @@ public:
|
|||||||
/// \c true if comments are allowed. Default: \c true.
|
/// \c true if comments are allowed. Default: \c true.
|
||||||
bool allowComments_{true};
|
bool allowComments_{true};
|
||||||
|
|
||||||
/// \c true if trailing commas in objects and arrays are allowed. Default \c
|
|
||||||
/// true.
|
|
||||||
bool allowTrailingCommas_{true};
|
|
||||||
|
|
||||||
/// \c true if root must be either an array or an object value. Default: \c
|
/// \c true if root must be either an array or an object value. Default: \c
|
||||||
/// false.
|
/// false.
|
||||||
bool strictRoot_{false};
|
bool strictRoot_{false};
|
||||||
|
@ -67,7 +67,6 @@ Features Features::all() { return {}; }
|
|||||||
Features Features::strictMode() {
|
Features Features::strictMode() {
|
||||||
Features features;
|
Features features;
|
||||||
features.allowComments_ = false;
|
features.allowComments_ = false;
|
||||||
features.allowTrailingCommas_ = false;
|
|
||||||
features.strictRoot_ = true;
|
features.strictRoot_ = true;
|
||||||
features.allowDroppedNullPlaceholders_ = false;
|
features.allowDroppedNullPlaceholders_ = false;
|
||||||
features.allowNumericKeys_ = false;
|
features.allowNumericKeys_ = false;
|
||||||
@ -455,9 +454,7 @@ bool Reader::readObject(Token& token) {
|
|||||||
initialTokenOk = readToken(tokenName);
|
initialTokenOk = readToken(tokenName);
|
||||||
if (!initialTokenOk)
|
if (!initialTokenOk)
|
||||||
break;
|
break;
|
||||||
if (tokenName.type_ == tokenObjectEnd &&
|
if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
|
||||||
(name.empty() ||
|
|
||||||
features_.allowTrailingCommas_)) // empty object or trailing comma
|
|
||||||
return true;
|
return true;
|
||||||
name.clear();
|
name.clear();
|
||||||
if (tokenName.type_ == tokenString) {
|
if (tokenName.type_ == tokenString) {
|
||||||
@ -505,20 +502,15 @@ bool Reader::readArray(Token& token) {
|
|||||||
Value init(arrayValue);
|
Value init(arrayValue);
|
||||||
currentValue().swapPayload(init);
|
currentValue().swapPayload(init);
|
||||||
currentValue().setOffsetStart(token.start_ - begin_);
|
currentValue().setOffsetStart(token.start_ - begin_);
|
||||||
|
skipSpaces();
|
||||||
|
if (current_ != end_ && *current_ == ']') // empty array
|
||||||
|
{
|
||||||
|
Token endArray;
|
||||||
|
readToken(endArray);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
skipSpaces();
|
|
||||||
if (current_ != end_ && *current_ == ']' &&
|
|
||||||
(index == 0 ||
|
|
||||||
(features_.allowTrailingCommas_ &&
|
|
||||||
!features_.allowDroppedNullPlaceholders_))) // empty array or trailing
|
|
||||||
// comma
|
|
||||||
{
|
|
||||||
Token endArray;
|
|
||||||
readToken(endArray);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value& value = currentValue()[index++];
|
Value& value = currentValue()[index++];
|
||||||
nodes_.push(&value);
|
nodes_.push(&value);
|
||||||
bool ok = readValue();
|
bool ok = readValue();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user