Changing 'enum' to 'enum class'

Fix for Visual Studio warning - Warning C26812: Enum type is unscoped. Prefer enum class over enum

Signed-off-by: ganeshkamath89 <ganeshkamath89@gmail.com>
This commit is contained in:
gakamath 2022-12-28 11:37:16 +05:30
parent 8190e061bc
commit 6a304af819
5 changed files with 442 additions and 416 deletions

View File

@ -156,7 +156,7 @@ public:
bool good() const; bool good() const;
private: private:
enum TokenType { enum class TokenType {
tokenEndOfStream = 0, tokenEndOfStream = 0,
tokenObjectBegin, tokenObjectBegin,
tokenObjectEnd, tokenObjectEnd,

View File

@ -105,7 +105,7 @@ JSONCPP_NORETURN void throwLogicError(String const& msg);
/** \brief Type of the value held by a Value object. /** \brief Type of the value held by a Value object.
*/ */
enum ValueType { enum class ValueType {
nullValue = 0, ///< 'null' value nullValue = 0, ///< 'null' value
intValue, ///< signed integer value intValue, ///< signed integer value
uintValue, ///< unsigned integer value uintValue, ///< unsigned integer value
@ -116,7 +116,7 @@ enum ValueType {
objectValue ///< object value (collection of name/value pairs). objectValue ///< object value (collection of name/value pairs).
}; };
enum CommentPlacement { enum class CommentPlacement {
commentBefore = 0, ///< a comment placed on the line before a value commentBefore = 0, ///< a comment placed on the line before a value
commentAfterOnSameLine, ///< a comment just after a value on the same line commentAfterOnSameLine, ///< a comment just after a value on the same line
commentAfter, ///< a comment on the line after a value (only make sense for commentAfter, ///< a comment on the line after a value (only make sense for
@ -126,7 +126,7 @@ enum CommentPlacement {
/** \brief Type of precision for formatting of real values. /** \brief Type of precision for formatting of real values.
*/ */
enum PrecisionType { enum class PrecisionType {
significantDigits = 0, ///< we set max number of significant digits in string significantDigits = 0, ///< we set max number of significant digits in string
decimalPlaces ///< we set max number of digits after "." in string decimalPlaces ///< we set max number of digits after "." in string
}; };
@ -260,7 +260,11 @@ private:
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
class CZString { class CZString {
public: public:
enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy }; enum class DuplicationPolicy {
noDuplication = 0,
duplicate,
duplicateOnCopy
};
CZString(ArrayIndex index); CZString(ArrayIndex index);
CZString(char const* str, unsigned length, DuplicationPolicy allocate); CZString(char const* str, unsigned length, DuplicationPolicy allocate);
CZString(CZString const& other); CZString(CZString const& other);
@ -313,7 +317,7 @@ public:
* Json::Value obj_value(Json::objectValue); // {} * Json::Value obj_value(Json::objectValue); // {}
* \endcode * \endcode
*/ */
Value(ValueType type = nullValue); Value(ValueType type = ValueType::nullValue);
Value(Int value); Value(Int value);
Value(UInt value); Value(UInt value);
#if defined(JSON_HAS_INT64) #if defined(JSON_HAS_INT64)
@ -644,7 +648,7 @@ private:
void set(CommentPlacement slot, String comment); void set(CommentPlacement slot, String comment);
private: private:
using Array = std::array<String, numberOfCommentPlacement>; using Array = std::array<String, (size_t)(CommentPlacement::numberOfCommentPlacement)>;
std::unique_ptr<Array> ptr_; std::unique_ptr<Array> ptr_;
}; };
Comments comments_; Comments comments_;
@ -698,10 +702,14 @@ public:
PathArgument(String key); PathArgument(String key);
private: private:
enum Kind { kindNone = 0, kindIndex, kindKey }; enum class Kind {
kindNone = 0,
kindIndex,
kindKey
};
String key_; String key_;
ArrayIndex index_{}; ArrayIndex index_{};
Kind kind_{kindNone}; Kind kind_{Kind::kindNone};
}; };
/** \brief Experimental and untested: represents a "path" to access a node. /** \brief Experimental and untested: represents a "path" to access a node.

View File

@ -131,12 +131,12 @@ bool Reader::parse(const char* beginDoc, const char* endDoc, Value& root,
Token token; Token token;
skipCommentTokens(token); skipCommentTokens(token);
if (collectComments_ && !commentsBefore_.empty()) if (collectComments_ && !commentsBefore_.empty())
root.setComment(commentsBefore_, commentAfter); root.setComment(commentsBefore_, CommentPlacement::commentAfter);
if (features_.strictRoot_) { if (features_.strictRoot_) {
if (!root.isArray() && !root.isObject()) { if (!root.isArray() && !root.isObject()) {
// Set error location to start of doc, ideally should be first token found // Set error location to start of doc, ideally should be first token found
// in doc // in doc
token.type_ = tokenError; token.type_ = TokenType::tokenError;
token.start_ = beginDoc; token.start_ = beginDoc;
token.end_ = endDoc; token.end_ = endDoc;
addError( addError(
@ -161,46 +161,46 @@ bool Reader::readValue() {
bool successful = true; bool successful = true;
if (collectComments_ && !commentsBefore_.empty()) { if (collectComments_ && !commentsBefore_.empty()) {
currentValue().setComment(commentsBefore_, commentBefore); currentValue().setComment(commentsBefore_, CommentPlacement::commentBefore);
commentsBefore_.clear(); commentsBefore_.clear();
} }
switch (token.type_) { switch (token.type_) {
case tokenObjectBegin: case TokenType::tokenObjectBegin:
successful = readObject(token); successful = readObject(token);
currentValue().setOffsetLimit(current_ - begin_); currentValue().setOffsetLimit(current_ - begin_);
break; break;
case tokenArrayBegin: case TokenType::tokenArrayBegin:
successful = readArray(token); successful = readArray(token);
currentValue().setOffsetLimit(current_ - begin_); currentValue().setOffsetLimit(current_ - begin_);
break; break;
case tokenNumber: case TokenType::tokenNumber:
successful = decodeNumber(token); successful = decodeNumber(token);
break; break;
case tokenString: case TokenType::tokenString:
successful = decodeString(token); successful = decodeString(token);
break; break;
case tokenTrue: { case TokenType::tokenTrue: {
Value v(true); Value v(true);
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenFalse: { case TokenType::tokenFalse: {
Value v(false); Value v(false);
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenNull: { case TokenType::tokenNull: {
Value v; Value v;
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenArraySeparator: case TokenType::tokenArraySeparator:
case tokenObjectEnd: case TokenType::tokenObjectEnd:
case tokenArrayEnd: case TokenType::tokenArrayEnd:
if (features_.allowDroppedNullPlaceholders_) { if (features_.allowDroppedNullPlaceholders_) {
// "Un-read" the current token and mark the current value as a null // "Un-read" the current token and mark the current value as a null
// token. // token.
@ -210,7 +210,8 @@ bool Reader::readValue() {
currentValue().setOffsetStart(current_ - begin_ - 1); currentValue().setOffsetStart(current_ - begin_ - 1);
currentValue().setOffsetLimit(current_ - begin_); currentValue().setOffsetLimit(current_ - begin_);
break; break;
} // Else, fall through... }
[[fallthrough]]; // Else, fall through...
default: default:
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
@ -229,7 +230,7 @@ void Reader::skipCommentTokens(Token& token) {
if (features_.allowComments_) { if (features_.allowComments_) {
do { do {
readToken(token); readToken(token);
} while (token.type_ == tokenComment); } while (token.type_ == TokenType::tokenComment);
} else { } else {
readToken(token); readToken(token);
} }
@ -242,23 +243,23 @@ bool Reader::readToken(Token& token) {
bool ok = true; bool ok = true;
switch (c) { switch (c) {
case '{': case '{':
token.type_ = tokenObjectBegin; token.type_ = TokenType::tokenObjectBegin;
break; break;
case '}': case '}':
token.type_ = tokenObjectEnd; token.type_ = TokenType::tokenObjectEnd;
break; break;
case '[': case '[':
token.type_ = tokenArrayBegin; token.type_ = TokenType::tokenArrayBegin;
break; break;
case ']': case ']':
token.type_ = tokenArrayEnd; token.type_ = TokenType::tokenArrayEnd;
break; break;
case '"': case '"':
token.type_ = tokenString; token.type_ = TokenType::tokenString;
ok = readString(); ok = readString();
break; break;
case '/': case '/':
token.type_ = tokenComment; token.type_ = TokenType::tokenComment;
ok = readComment(); ok = readComment();
break; break;
case '0': case '0':
@ -272,36 +273,36 @@ bool Reader::readToken(Token& token) {
case '8': case '8':
case '9': case '9':
case '-': case '-':
token.type_ = tokenNumber; token.type_ = TokenType::tokenNumber;
readNumber(); readNumber();
break; break;
case 't': case 't':
token.type_ = tokenTrue; token.type_ = TokenType::tokenTrue;
ok = match("rue", 3); ok = match("rue", 3);
break; break;
case 'f': case 'f':
token.type_ = tokenFalse; token.type_ = TokenType::tokenFalse;
ok = match("alse", 4); ok = match("alse", 4);
break; break;
case 'n': case 'n':
token.type_ = tokenNull; token.type_ = TokenType::tokenNull;
ok = match("ull", 3); ok = match("ull", 3);
break; break;
case ',': case ',':
token.type_ = tokenArraySeparator; token.type_ = TokenType::tokenArraySeparator;
break; break;
case ':': case ':':
token.type_ = tokenMemberSeparator; token.type_ = TokenType::tokenMemberSeparator;
break; break;
case 0: case 0:
token.type_ = tokenEndOfStream; token.type_ = TokenType::tokenEndOfStream;
break; break;
default: default:
ok = false; ok = false;
break; break;
} }
if (!ok) if (!ok)
token.type_ = tokenError; token.type_ = TokenType::tokenError;
token.end_ = current_; token.end_ = current_;
return ok; return ok;
} }
@ -339,10 +340,10 @@ bool Reader::readComment() {
return false; return false;
if (collectComments_) { if (collectComments_) {
CommentPlacement placement = commentBefore; CommentPlacement placement = CommentPlacement::commentBefore;
if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) { if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) {
if (c != '*' || !containsNewLine(commentBegin, current_)) if (c != '*' || !containsNewLine(commentBegin, current_))
placement = commentAfterOnSameLine; placement = CommentPlacement::commentAfterOnSameLine;
} }
addComment(commentBegin, current_, placement); addComment(commentBegin, current_, placement);
@ -373,7 +374,7 @@ void Reader::addComment(Location begin, Location end,
CommentPlacement placement) { CommentPlacement placement) {
assert(collectComments_); assert(collectComments_);
const String& normalized = normalizeEOL(begin, end); const String& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) { if (placement == CommentPlacement::commentAfterOnSameLine) {
assert(lastValue_ != nullptr); assert(lastValue_ != nullptr);
lastValue_->setComment(normalized, placement); lastValue_->setComment(normalized, placement);
} else { } else {
@ -443,61 +444,61 @@ bool Reader::readString() {
bool Reader::readObject(Token& token) { bool Reader::readObject(Token& token) {
Token tokenName; Token tokenName;
String name; String name;
Value init(objectValue); Value init(ValueType::objectValue);
currentValue().swapPayload(init); currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
while (readToken(tokenName)) { while (readToken(tokenName)) {
bool initialTokenOk = true; bool initialTokenOk = true;
while (tokenName.type_ == tokenComment && initialTokenOk) while (tokenName.type_ == TokenType::tokenComment && initialTokenOk)
initialTokenOk = readToken(tokenName); initialTokenOk = readToken(tokenName);
if (!initialTokenOk) if (!initialTokenOk)
break; break;
if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object if (tokenName.type_ == TokenType::tokenObjectEnd && name.empty()) // empty object
return true; return true;
name.clear(); name.clear();
if (tokenName.type_ == tokenString) { if (tokenName.type_ == TokenType::tokenString) {
if (!decodeString(tokenName, name)) if (!decodeString(tokenName, name))
return recoverFromError(tokenObjectEnd); return recoverFromError(TokenType::tokenObjectEnd);
} else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { } else if (tokenName.type_ == TokenType::tokenNumber && features_.allowNumericKeys_) {
Value numberName; Value numberName;
if (!decodeNumber(tokenName, numberName)) if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd); return recoverFromError(TokenType::tokenObjectEnd);
name = numberName.asString(); name = numberName.asString();
} else { } else {
break; break;
} }
Token colon; Token colon;
if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { if (!readToken(colon) || colon.type_ != TokenType::tokenMemberSeparator) {
return addErrorAndRecover("Missing ':' after object member name", colon, return addErrorAndRecover("Missing ':' after object member name", colon,
tokenObjectEnd); TokenType::tokenObjectEnd);
} }
Value& value = currentValue()[name]; Value& value = currentValue()[name];
nodes_.push(&value); nodes_.push(&value);
bool ok = readValue(); bool ok = readValue();
nodes_.pop(); nodes_.pop();
if (!ok) // error already set if (!ok) // error already set
return recoverFromError(tokenObjectEnd); return recoverFromError(TokenType::tokenObjectEnd);
Token comma; Token comma;
if (!readToken(comma) || if (!readToken(comma) ||
(comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && (comma.type_ != TokenType::tokenObjectEnd && comma.type_ != TokenType::tokenArraySeparator &&
comma.type_ != tokenComment)) { comma.type_ != TokenType::tokenComment)) {
return addErrorAndRecover("Missing ',' or '}' in object declaration", return addErrorAndRecover("Missing ',' or '}' in object declaration",
comma, tokenObjectEnd); comma, TokenType::tokenObjectEnd);
} }
bool finalizeTokenOk = true; bool finalizeTokenOk = true;
while (comma.type_ == tokenComment && finalizeTokenOk) while (comma.type_ == TokenType::tokenComment && finalizeTokenOk)
finalizeTokenOk = readToken(comma); finalizeTokenOk = readToken(comma);
if (comma.type_ == tokenObjectEnd) if (comma.type_ == TokenType::tokenObjectEnd)
return true; return true;
} }
return addErrorAndRecover("Missing '}' or object member name", tokenName, return addErrorAndRecover("Missing '}' or object member name", tokenName,
tokenObjectEnd); TokenType::tokenObjectEnd);
} }
bool Reader::readArray(Token& token) { bool Reader::readArray(Token& token) {
Value init(arrayValue); Value init(ValueType::arrayValue);
currentValue().swapPayload(init); currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
skipSpaces(); skipSpaces();
@ -514,21 +515,21 @@ bool Reader::readArray(Token& token) {
bool ok = readValue(); bool ok = readValue();
nodes_.pop(); nodes_.pop();
if (!ok) // error already set if (!ok) // error already set
return recoverFromError(tokenArrayEnd); return recoverFromError(TokenType::tokenArrayEnd);
Token currentToken; Token currentToken;
// Accept Comment after last item in the array. // Accept Comment after last item in the array.
ok = readToken(currentToken); ok = readToken(currentToken);
while (currentToken.type_ == tokenComment && ok) { while (currentToken.type_ == TokenType::tokenComment && ok) {
ok = readToken(currentToken); ok = readToken(currentToken);
} }
bool badTokenType = (currentToken.type_ != tokenArraySeparator && bool badTokenType = (currentToken.type_ != TokenType::tokenArraySeparator &&
currentToken.type_ != tokenArrayEnd); currentToken.type_ != TokenType::tokenArrayEnd);
if (!ok || badTokenType) { if (!ok || badTokenType) {
return addErrorAndRecover("Missing ',' or ']' in array declaration", return addErrorAndRecover("Missing ',' or ']' in array declaration",
currentToken, tokenArrayEnd); currentToken, TokenType::tokenArrayEnd);
} }
if (currentToken.type_ == tokenArrayEnd) if (currentToken.type_ == TokenType::tokenArrayEnd)
break; break;
} }
return true; return true;
@ -744,7 +745,7 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
for (;;) { for (;;) {
if (!readToken(skip)) if (!readToken(skip))
errors_.resize(errorCount); // discard errors caused by recovery errors_.resize(errorCount); // discard errors caused by recovery
if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream) if (skip.type_ == skipUntilToken || skip.type_ == TokenType::tokenEndOfStream)
break; break;
} }
errors_.resize(errorCount); errors_.resize(errorCount);
@ -830,7 +831,7 @@ bool Reader::pushError(const Value& value, const String& message) {
if (value.getOffsetStart() > length || value.getOffsetLimit() > length) if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
return false; return false;
Token token; Token token;
token.type_ = tokenError; token.type_ = TokenType::tokenError;
token.start_ = begin_ + value.getOffsetStart(); token.start_ = begin_ + value.getOffsetStart();
token.end_ = begin_ + value.getOffsetLimit(); token.end_ = begin_ + value.getOffsetLimit();
ErrorInfo info; ErrorInfo info;
@ -848,7 +849,7 @@ bool Reader::pushError(const Value& value, const String& message,
extra.getOffsetLimit() > length) extra.getOffsetLimit() > length)
return false; return false;
Token token; Token token;
token.type_ = tokenError; token.type_ = TokenType::tokenError;
token.start_ = begin_ + value.getOffsetStart(); token.start_ = begin_ + value.getOffsetStart();
token.end_ = begin_ + value.getOffsetLimit(); token.end_ = begin_ + value.getOffsetLimit();
ErrorInfo info; ErrorInfo info;
@ -906,7 +907,7 @@ private:
OurReader(OurReader const&); // no impl OurReader(OurReader const&); // no impl
void operator=(OurReader const&); // no impl void operator=(OurReader const&); // no impl
enum TokenType { enum class TokenType {
tokenEndOfStream = 0, tokenEndOfStream = 0,
tokenObjectBegin, tokenObjectBegin,
tokenObjectEnd, tokenObjectEnd,
@ -1031,17 +1032,17 @@ bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
nodes_.pop(); nodes_.pop();
Token token; Token token;
skipCommentTokens(token); skipCommentTokens(token);
if (features_.failIfExtra_ && (token.type_ != tokenEndOfStream)) { if (features_.failIfExtra_ && (token.type_ != TokenType::tokenEndOfStream)) {
addError("Extra non-whitespace after JSON value.", token); addError("Extra non-whitespace after JSON value.", token);
return false; return false;
} }
if (collectComments_ && !commentsBefore_.empty()) if (collectComments_ && !commentsBefore_.empty())
root.setComment(commentsBefore_, commentAfter); root.setComment(commentsBefore_, CommentPlacement::commentAfter);
if (features_.strictRoot_) { if (features_.strictRoot_) {
if (!root.isArray() && !root.isObject()) { if (!root.isArray() && !root.isObject()) {
// Set error location to start of doc, ideally should be first token found // Set error location to start of doc, ideally should be first token found
// in doc // in doc
token.type_ = tokenError; token.type_ = TokenType::tokenError;
token.start_ = beginDoc; token.start_ = beginDoc;
token.end_ = endDoc; token.end_ = endDoc;
addError( addError(
@ -1062,64 +1063,64 @@ bool OurReader::readValue() {
bool successful = true; bool successful = true;
if (collectComments_ && !commentsBefore_.empty()) { if (collectComments_ && !commentsBefore_.empty()) {
currentValue().setComment(commentsBefore_, commentBefore); currentValue().setComment(commentsBefore_, CommentPlacement::commentBefore);
commentsBefore_.clear(); commentsBefore_.clear();
} }
switch (token.type_) { switch (token.type_) {
case tokenObjectBegin: case TokenType::tokenObjectBegin:
successful = readObject(token); successful = readObject(token);
currentValue().setOffsetLimit(current_ - begin_); currentValue().setOffsetLimit(current_ - begin_);
break; break;
case tokenArrayBegin: case TokenType::tokenArrayBegin:
successful = readArray(token); successful = readArray(token);
currentValue().setOffsetLimit(current_ - begin_); currentValue().setOffsetLimit(current_ - begin_);
break; break;
case tokenNumber: case TokenType::tokenNumber:
successful = decodeNumber(token); successful = decodeNumber(token);
break; break;
case tokenString: case TokenType::tokenString:
successful = decodeString(token); successful = decodeString(token);
break; break;
case tokenTrue: { case TokenType::tokenTrue: {
Value v(true); Value v(true);
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenFalse: { case TokenType::tokenFalse: {
Value v(false); Value v(false);
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenNull: { case TokenType::tokenNull: {
Value v; Value v;
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenNaN: { case TokenType::tokenNaN: {
Value v(std::numeric_limits<double>::quiet_NaN()); Value v(std::numeric_limits<double>::quiet_NaN());
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenPosInf: { case TokenType::tokenPosInf: {
Value v(std::numeric_limits<double>::infinity()); Value v(std::numeric_limits<double>::infinity());
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenNegInf: { case TokenType::tokenNegInf: {
Value v(-std::numeric_limits<double>::infinity()); Value v(-std::numeric_limits<double>::infinity());
currentValue().swapPayload(v); currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
} break; } break;
case tokenArraySeparator: case TokenType::tokenArraySeparator:
case tokenObjectEnd: case TokenType::tokenObjectEnd:
case tokenArrayEnd: case TokenType::tokenArrayEnd:
if (features_.allowDroppedNullPlaceholders_) { if (features_.allowDroppedNullPlaceholders_) {
// "Un-read" the current token and mark the current value as a null // "Un-read" the current token and mark the current value as a null
// token. // token.
@ -1129,7 +1130,8 @@ bool OurReader::readValue() {
currentValue().setOffsetStart(current_ - begin_ - 1); currentValue().setOffsetStart(current_ - begin_ - 1);
currentValue().setOffsetLimit(current_ - begin_); currentValue().setOffsetLimit(current_ - begin_);
break; break;
} // else, fall through ... }
[[fallthrough]]; // Else, fall through...
default: default:
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_);
@ -1149,7 +1151,7 @@ void OurReader::skipCommentTokens(Token& token) {
if (features_.allowComments_) { if (features_.allowComments_) {
do { do {
readToken(token); readToken(token);
} while (token.type_ == tokenComment); } while (token.type_ == TokenType::tokenComment);
} else { } else {
readToken(token); readToken(token);
} }
@ -1162,24 +1164,24 @@ bool OurReader::readToken(Token& token) {
bool ok = true; bool ok = true;
switch (c) { switch (c) {
case '{': case '{':
token.type_ = tokenObjectBegin; token.type_ = TokenType::tokenObjectBegin;
break; break;
case '}': case '}':
token.type_ = tokenObjectEnd; token.type_ = TokenType::tokenObjectEnd;
break; break;
case '[': case '[':
token.type_ = tokenArrayBegin; token.type_ = TokenType::tokenArrayBegin;
break; break;
case ']': case ']':
token.type_ = tokenArrayEnd; token.type_ = TokenType::tokenArrayEnd;
break; break;
case '"': case '"':
token.type_ = tokenString; token.type_ = TokenType::tokenString;
ok = readString(); ok = readString();
break; break;
case '\'': case '\'':
if (features_.allowSingleQuotes_) { if (features_.allowSingleQuotes_) {
token.type_ = tokenString; token.type_ = TokenType::tokenString;
ok = readStringSingleQuote(); ok = readStringSingleQuote();
} else { } else {
// If we don't allow single quotes, this is a failure case. // If we don't allow single quotes, this is a failure case.
@ -1187,7 +1189,7 @@ bool OurReader::readToken(Token& token) {
} }
break; break;
case '/': case '/':
token.type_ = tokenComment; token.type_ = TokenType::tokenComment;
ok = readComment(); ok = readComment();
break; break;
case '0': case '0':
@ -1200,40 +1202,40 @@ bool OurReader::readToken(Token& token) {
case '7': case '7':
case '8': case '8':
case '9': case '9':
token.type_ = tokenNumber; token.type_ = TokenType::tokenNumber;
readNumber(false); readNumber(false);
break; break;
case '-': case '-':
if (readNumber(true)) { if (readNumber(true)) {
token.type_ = tokenNumber; token.type_ = TokenType::tokenNumber;
} else { } else {
token.type_ = tokenNegInf; token.type_ = TokenType::tokenNegInf;
ok = features_.allowSpecialFloats_ && match("nfinity", 7); ok = features_.allowSpecialFloats_ && match("nfinity", 7);
} }
break; break;
case '+': case '+':
if (readNumber(true)) { if (readNumber(true)) {
token.type_ = tokenNumber; token.type_ = TokenType::tokenNumber;
} else { } else {
token.type_ = tokenPosInf; token.type_ = TokenType::tokenPosInf;
ok = features_.allowSpecialFloats_ && match("nfinity", 7); ok = features_.allowSpecialFloats_ && match("nfinity", 7);
} }
break; break;
case 't': case 't':
token.type_ = tokenTrue; token.type_ = TokenType::tokenTrue;
ok = match("rue", 3); ok = match("rue", 3);
break; break;
case 'f': case 'f':
token.type_ = tokenFalse; token.type_ = TokenType::tokenFalse;
ok = match("alse", 4); ok = match("alse", 4);
break; break;
case 'n': case 'n':
token.type_ = tokenNull; token.type_ = TokenType::tokenNull;
ok = match("ull", 3); ok = match("ull", 3);
break; break;
case 'N': case 'N':
if (features_.allowSpecialFloats_) { if (features_.allowSpecialFloats_) {
token.type_ = tokenNaN; token.type_ = TokenType::tokenNaN;
ok = match("aN", 2); ok = match("aN", 2);
} else { } else {
ok = false; ok = false;
@ -1241,27 +1243,27 @@ bool OurReader::readToken(Token& token) {
break; break;
case 'I': case 'I':
if (features_.allowSpecialFloats_) { if (features_.allowSpecialFloats_) {
token.type_ = tokenPosInf; token.type_ = TokenType::tokenPosInf;
ok = match("nfinity", 7); ok = match("nfinity", 7);
} else { } else {
ok = false; ok = false;
} }
break; break;
case ',': case ',':
token.type_ = tokenArraySeparator; token.type_ = TokenType::tokenArraySeparator;
break; break;
case ':': case ':':
token.type_ = tokenMemberSeparator; token.type_ = TokenType::tokenMemberSeparator;
break; break;
case 0: case 0:
token.type_ = tokenEndOfStream; token.type_ = TokenType::tokenEndOfStream;
break; break;
default: default:
ok = false; ok = false;
break; break;
} }
if (!ok) if (!ok)
token.type_ = tokenError; token.type_ = TokenType::tokenError;
token.end_ = current_; token.end_ = current_;
return ok; return ok;
} }
@ -1315,12 +1317,12 @@ bool OurReader::readComment() {
return false; return false;
if (collectComments_) { if (collectComments_) {
CommentPlacement placement = commentBefore; CommentPlacement placement = CommentPlacement::commentBefore;
if (!lastValueHasAComment_) { if (!lastValueHasAComment_) {
if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) { if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) {
if (isCppStyleComment || !cStyleWithEmbeddedNewline) { if (isCppStyleComment || !cStyleWithEmbeddedNewline) {
placement = commentAfterOnSameLine; placement = CommentPlacement::commentAfterOnSameLine;
lastValueHasAComment_ = true; lastValueHasAComment_ = true;
} }
} }
@ -1355,7 +1357,7 @@ void OurReader::addComment(Location begin, Location end,
CommentPlacement placement) { CommentPlacement placement) {
assert(collectComments_); assert(collectComments_);
const String& normalized = normalizeEOL(begin, end); const String& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) { if (placement == CommentPlacement::commentAfterOnSameLine) {
assert(lastValue_ != nullptr); assert(lastValue_ != nullptr);
lastValue_->setComment(normalized, placement); lastValue_->setComment(normalized, placement);
} else { } else {
@ -1446,27 +1448,27 @@ bool OurReader::readStringSingleQuote() {
bool OurReader::readObject(Token& token) { bool OurReader::readObject(Token& token) {
Token tokenName; Token tokenName;
String name; String name;
Value init(objectValue); Value init(ValueType::objectValue);
currentValue().swapPayload(init); currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
while (readToken(tokenName)) { while (readToken(tokenName)) {
bool initialTokenOk = true; bool initialTokenOk = true;
while (tokenName.type_ == tokenComment && initialTokenOk) while (tokenName.type_ == TokenType::tokenComment && initialTokenOk)
initialTokenOk = readToken(tokenName); initialTokenOk = readToken(tokenName);
if (!initialTokenOk) if (!initialTokenOk)
break; break;
if (tokenName.type_ == tokenObjectEnd && if (tokenName.type_ == TokenType::tokenObjectEnd &&
(name.empty() || (name.empty() ||
features_.allowTrailingCommas_)) // empty object or trailing comma features_.allowTrailingCommas_)) // empty object or trailing comma
return true; return true;
name.clear(); name.clear();
if (tokenName.type_ == tokenString) { if (tokenName.type_ == TokenType::tokenString) {
if (!decodeString(tokenName, name)) if (!decodeString(tokenName, name))
return recoverFromError(tokenObjectEnd); return recoverFromError(TokenType::tokenObjectEnd);
} else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { } else if (tokenName.type_ == TokenType::tokenNumber && features_.allowNumericKeys_) {
Value numberName; Value numberName;
if (!decodeNumber(tokenName, numberName)) if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd); return recoverFromError(TokenType::tokenObjectEnd);
name = numberName.asString(); name = numberName.asString();
} else { } else {
break; break;
@ -1475,40 +1477,40 @@ bool OurReader::readObject(Token& token) {
throwRuntimeError("keylength >= 2^30"); throwRuntimeError("keylength >= 2^30");
if (features_.rejectDupKeys_ && currentValue().isMember(name)) { if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
String msg = "Duplicate key: '" + name + "'"; String msg = "Duplicate key: '" + name + "'";
return addErrorAndRecover(msg, tokenName, tokenObjectEnd); return addErrorAndRecover(msg, tokenName, TokenType::tokenObjectEnd);
} }
Token colon; Token colon;
if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { if (!readToken(colon) || colon.type_ != TokenType::tokenMemberSeparator) {
return addErrorAndRecover("Missing ':' after object member name", colon, return addErrorAndRecover("Missing ':' after object member name", colon,
tokenObjectEnd); TokenType::tokenObjectEnd);
} }
Value& value = currentValue()[name]; Value& value = currentValue()[name];
nodes_.push(&value); nodes_.push(&value);
bool ok = readValue(); bool ok = readValue();
nodes_.pop(); nodes_.pop();
if (!ok) // error already set if (!ok) // error already set
return recoverFromError(tokenObjectEnd); return recoverFromError(TokenType::tokenObjectEnd);
Token comma; Token comma;
if (!readToken(comma) || if (!readToken(comma) ||
(comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && (comma.type_ != TokenType::tokenObjectEnd && comma.type_ != TokenType::tokenArraySeparator &&
comma.type_ != tokenComment)) { comma.type_ != TokenType::tokenComment)) {
return addErrorAndRecover("Missing ',' or '}' in object declaration", return addErrorAndRecover("Missing ',' or '}' in object declaration",
comma, tokenObjectEnd); comma, TokenType::tokenObjectEnd);
} }
bool finalizeTokenOk = true; bool finalizeTokenOk = true;
while (comma.type_ == tokenComment && finalizeTokenOk) while (comma.type_ == TokenType::tokenComment && finalizeTokenOk)
finalizeTokenOk = readToken(comma); finalizeTokenOk = readToken(comma);
if (comma.type_ == tokenObjectEnd) if (comma.type_ == TokenType::tokenObjectEnd)
return true; return true;
} }
return addErrorAndRecover("Missing '}' or object member name", tokenName, return addErrorAndRecover("Missing '}' or object member name", tokenName,
tokenObjectEnd); TokenType::tokenObjectEnd);
} }
bool OurReader::readArray(Token& token) { bool OurReader::readArray(Token& token) {
Value init(arrayValue); Value init(ValueType::arrayValue);
currentValue().swapPayload(init); currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetStart(token.start_ - begin_);
int index = 0; int index = 0;
@ -1529,21 +1531,21 @@ bool OurReader::readArray(Token& token) {
bool ok = readValue(); bool ok = readValue();
nodes_.pop(); nodes_.pop();
if (!ok) // error already set if (!ok) // error already set
return recoverFromError(tokenArrayEnd); return recoverFromError(TokenType::tokenArrayEnd);
Token currentToken; Token currentToken;
// Accept Comment after last item in the array. // Accept Comment after last item in the array.
ok = readToken(currentToken); ok = readToken(currentToken);
while (currentToken.type_ == tokenComment && ok) { while (currentToken.type_ == TokenType::tokenComment && ok) {
ok = readToken(currentToken); ok = readToken(currentToken);
} }
bool badTokenType = (currentToken.type_ != tokenArraySeparator && bool badTokenType = (currentToken.type_ != TokenType::tokenArraySeparator &&
currentToken.type_ != tokenArrayEnd); currentToken.type_ != TokenType::tokenArrayEnd);
if (!ok || badTokenType) { if (!ok || badTokenType) {
return addErrorAndRecover("Missing ',' or ']' in array declaration", return addErrorAndRecover("Missing ',' or ']' in array declaration",
currentToken, tokenArrayEnd); currentToken, TokenType::tokenArrayEnd);
} }
if (currentToken.type_ == tokenArrayEnd) if (currentToken.type_ == TokenType::tokenArrayEnd)
break; break;
} }
return true; return true;
@ -1796,7 +1798,7 @@ bool OurReader::recoverFromError(TokenType skipUntilToken) {
for (;;) { for (;;) {
if (!readToken(skip)) if (!readToken(skip))
errors_.resize(errorCount); // discard errors caused by recovery errors_.resize(errorCount); // discard errors caused by recovery
if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream) if (skip.type_ == skipUntilToken || skip.type_ == TokenType::tokenEndOfStream)
break; break;
} }
errors_.resize(errorCount); errors_.resize(errorCount);

File diff suppressed because it is too large Load Diff

View File

@ -380,20 +380,20 @@ String FastWriter::write(const Value& root) {
void FastWriter::writeValue(const Value& value) { void FastWriter::writeValue(const Value& value) {
switch (value.type()) { switch (value.type()) {
case nullValue: case ValueType::nullValue:
if (!dropNullPlaceholders_) if (!dropNullPlaceholders_)
document_ += "null"; document_ += "null";
break; break;
case intValue: case ValueType::intValue:
document_ += valueToString(value.asLargestInt()); document_ += valueToString(value.asLargestInt());
break; break;
case uintValue: case ValueType::uintValue:
document_ += valueToString(value.asLargestUInt()); document_ += valueToString(value.asLargestUInt());
break; break;
case realValue: case ValueType::realValue:
document_ += valueToString(value.asDouble()); document_ += valueToString(value.asDouble());
break; break;
case stringValue: { case ValueType::stringValue: {
// Is NULL possible for value.string_? No. // Is NULL possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
@ -402,10 +402,10 @@ void FastWriter::writeValue(const Value& value) {
document_ += valueToQuotedStringN(str, static_cast<size_t>(end - str)); document_ += valueToQuotedStringN(str, static_cast<size_t>(end - str));
break; break;
} }
case booleanValue: case ValueType::booleanValue:
document_ += valueToString(value.asBool()); document_ += valueToString(value.asBool());
break; break;
case arrayValue: { case ValueType::arrayValue: {
document_ += '['; document_ += '[';
ArrayIndex size = value.size(); ArrayIndex size = value.size();
for (ArrayIndex index = 0; index < size; ++index) { for (ArrayIndex index = 0; index < size; ++index) {
@ -415,7 +415,7 @@ void FastWriter::writeValue(const Value& value) {
} }
document_ += ']'; document_ += ']';
} break; } break;
case objectValue: { case ValueType::objectValue: {
Value::Members members(value.getMemberNames()); Value::Members members(value.getMemberNames());
document_ += '{'; document_ += '{';
for (auto it = members.begin(); it != members.end(); ++it) { for (auto it = members.begin(); it != members.end(); ++it) {
@ -449,19 +449,19 @@ String StyledWriter::write(const Value& root) {
void StyledWriter::writeValue(const Value& value) { void StyledWriter::writeValue(const Value& value) {
switch (value.type()) { switch (value.type()) {
case nullValue: case ValueType::nullValue:
pushValue("null"); pushValue("null");
break; break;
case intValue: case ValueType::intValue:
pushValue(valueToString(value.asLargestInt())); pushValue(valueToString(value.asLargestInt()));
break; break;
case uintValue: case ValueType::uintValue:
pushValue(valueToString(value.asLargestUInt())); pushValue(valueToString(value.asLargestUInt()));
break; break;
case realValue: case ValueType::realValue:
pushValue(valueToString(value.asDouble())); pushValue(valueToString(value.asDouble()));
break; break;
case stringValue: { case ValueType::stringValue: {
// Is NULL possible for value.string_? No. // Is NULL possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
@ -472,13 +472,13 @@ void StyledWriter::writeValue(const Value& value) {
pushValue(""); pushValue("");
break; break;
} }
case booleanValue: case ValueType::booleanValue:
pushValue(valueToString(value.asBool())); pushValue(valueToString(value.asBool()));
break; break;
case arrayValue: case ValueType::arrayValue:
writeArrayValue(value); writeArrayValue(value);
break; break;
case objectValue: { case ValueType::objectValue: {
Value::Members members(value.getMemberNames()); Value::Members members(value.getMemberNames());
if (members.empty()) if (members.empty())
pushValue("{}"); pushValue("{}");
@ -608,12 +608,12 @@ void StyledWriter::unindent() {
} }
void StyledWriter::writeCommentBeforeValue(const Value& root) { void StyledWriter::writeCommentBeforeValue(const Value& root) {
if (!root.hasComment(commentBefore)) if (!root.hasComment(CommentPlacement::commentBefore))
return; return;
document_ += '\n'; document_ += '\n';
writeIndent(); writeIndent();
const String& comment = root.getComment(commentBefore); const String& comment = root.getComment(CommentPlacement::commentBefore);
String::const_iterator iter = comment.begin(); String::const_iterator iter = comment.begin();
while (iter != comment.end()) { while (iter != comment.end()) {
document_ += *iter; document_ += *iter;
@ -627,20 +627,21 @@ void StyledWriter::writeCommentBeforeValue(const Value& root) {
} }
void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) { void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) {
if (root.hasComment(commentAfterOnSameLine)) if (root.hasComment(CommentPlacement::commentAfterOnSameLine))
document_ += " " + root.getComment(commentAfterOnSameLine); document_ +=
" " + root.getComment(CommentPlacement::commentAfterOnSameLine);
if (root.hasComment(commentAfter)) { if (root.hasComment(CommentPlacement::commentAfter)) {
document_ += '\n'; document_ += '\n';
document_ += root.getComment(commentAfter); document_ += root.getComment(CommentPlacement::commentAfter);
document_ += '\n'; document_ += '\n';
} }
} }
bool StyledWriter::hasCommentForValue(const Value& value) { bool StyledWriter::hasCommentForValue(const Value& value) {
return value.hasComment(commentBefore) || return value.hasComment(CommentPlacement::commentBefore) ||
value.hasComment(commentAfterOnSameLine) || value.hasComment(CommentPlacement::commentAfterOnSameLine) ||
value.hasComment(commentAfter); value.hasComment(CommentPlacement::commentAfter);
} }
// Class StyledStreamWriter // Class StyledStreamWriter
@ -667,19 +668,19 @@ void StyledStreamWriter::write(OStream& out, const Value& root) {
void StyledStreamWriter::writeValue(const Value& value) { void StyledStreamWriter::writeValue(const Value& value) {
switch (value.type()) { switch (value.type()) {
case nullValue: case ValueType::nullValue:
pushValue("null"); pushValue("null");
break; break;
case intValue: case ValueType::intValue:
pushValue(valueToString(value.asLargestInt())); pushValue(valueToString(value.asLargestInt()));
break; break;
case uintValue: case ValueType::uintValue:
pushValue(valueToString(value.asLargestUInt())); pushValue(valueToString(value.asLargestUInt()));
break; break;
case realValue: case ValueType::realValue:
pushValue(valueToString(value.asDouble())); pushValue(valueToString(value.asDouble()));
break; break;
case stringValue: { case ValueType::stringValue: {
// Is NULL possible for value.string_? No. // Is NULL possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
@ -690,13 +691,13 @@ void StyledStreamWriter::writeValue(const Value& value) {
pushValue(""); pushValue("");
break; break;
} }
case booleanValue: case ValueType::booleanValue:
pushValue(valueToString(value.asBool())); pushValue(valueToString(value.asBool()));
break; break;
case arrayValue: case ValueType::arrayValue:
writeArrayValue(value); writeArrayValue(value);
break; break;
case objectValue: { case ValueType::objectValue: {
Value::Members members(value.getMemberNames()); Value::Members members(value.getMemberNames());
if (members.empty()) if (members.empty())
pushValue("{}"); pushValue("{}");
@ -828,12 +829,12 @@ void StyledStreamWriter::unindent() {
} }
void StyledStreamWriter::writeCommentBeforeValue(const Value& root) { void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
if (!root.hasComment(commentBefore)) if (!root.hasComment(CommentPlacement::commentBefore))
return; return;
if (!indented_) if (!indented_)
writeIndent(); writeIndent();
const String& comment = root.getComment(commentBefore); const String& comment = root.getComment(CommentPlacement::commentBefore);
String::const_iterator iter = comment.begin(); String::const_iterator iter = comment.begin();
while (iter != comment.end()) { while (iter != comment.end()) {
*document_ << *iter; *document_ << *iter;
@ -846,20 +847,21 @@ void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
} }
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) { void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
if (root.hasComment(commentAfterOnSameLine)) if (root.hasComment(CommentPlacement::commentAfterOnSameLine))
*document_ << ' ' << root.getComment(commentAfterOnSameLine); *document_ << ' '
<< root.getComment(CommentPlacement::commentAfterOnSameLine);
if (root.hasComment(commentAfter)) { if (root.hasComment(CommentPlacement::commentAfter)) {
writeIndent(); writeIndent();
*document_ << root.getComment(commentAfter); *document_ << root.getComment(CommentPlacement::commentAfter);
} }
indented_ = false; indented_ = false;
} }
bool StyledStreamWriter::hasCommentForValue(const Value& value) { bool StyledStreamWriter::hasCommentForValue(const Value& value) {
return value.hasComment(commentBefore) || return value.hasComment(CommentPlacement::commentBefore) ||
value.hasComment(commentAfterOnSameLine) || value.hasComment(CommentPlacement::commentAfterOnSameLine) ||
value.hasComment(commentAfter); value.hasComment(CommentPlacement::commentAfter);
} }
////////////////////////// //////////////////////////
@ -868,7 +870,7 @@ bool StyledStreamWriter::hasCommentForValue(const Value& value) {
/// Scoped enums are not available until C++11. /// Scoped enums are not available until C++11.
struct CommentStyle { struct CommentStyle {
/// Decide whether to write comments. /// Decide whether to write comments.
enum Enum { enum class Enum {
None, ///< Drop all comments. None, ///< Drop all comments.
Most, ///< Recover odd behavior of previous versions (not implemented yet). Most, ///< Recover odd behavior of previous versions (not implemented yet).
All ///< Keep all comments. All ///< Keep all comments.
@ -940,20 +942,20 @@ int BuiltStyledStreamWriter::write(Value const& root, OStream* sout) {
} }
void BuiltStyledStreamWriter::writeValue(Value const& value) { void BuiltStyledStreamWriter::writeValue(Value const& value) {
switch (value.type()) { switch (value.type()) {
case nullValue: case ValueType::nullValue:
pushValue(nullSymbol_); pushValue(nullSymbol_);
break; break;
case intValue: case ValueType::intValue:
pushValue(valueToString(value.asLargestInt())); pushValue(valueToString(value.asLargestInt()));
break; break;
case uintValue: case ValueType::uintValue:
pushValue(valueToString(value.asLargestUInt())); pushValue(valueToString(value.asLargestUInt()));
break; break;
case realValue: case ValueType::realValue:
pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_, pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_,
precisionType_)); precisionType_));
break; break;
case stringValue: { case ValueType::stringValue: {
// Is NULL is possible for value.string_? No. // Is NULL is possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
@ -965,13 +967,13 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
pushValue(""); pushValue("");
break; break;
} }
case booleanValue: case ValueType::booleanValue:
pushValue(valueToString(value.asBool())); pushValue(valueToString(value.asBool()));
break; break;
case arrayValue: case ValueType::arrayValue:
writeArrayValue(value); writeArrayValue(value);
break; break;
case objectValue: { case ValueType::objectValue: {
Value::Members members(value.getMemberNames()); Value::Members members(value.getMemberNames());
if (members.empty()) if (members.empty())
pushValue("{}"); pushValue("{}");
@ -1006,7 +1008,7 @@ void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
if (size == 0) if (size == 0)
pushValue("[]"); pushValue("[]");
else { else {
bool isMultiLine = (cs_ == CommentStyle::All) || isMultilineArray(value); bool isMultiLine = (cs_ == CommentStyle::Enum::All) || isMultilineArray(value);
if (isMultiLine) { if (isMultiLine) {
writeWithIndent("["); writeWithIndent("[");
indent(); indent();
@ -1112,14 +1114,14 @@ void BuiltStyledStreamWriter::unindent() {
} }
void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) { void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
if (cs_ == CommentStyle::None) if (cs_ == CommentStyle::Enum::None)
return; return;
if (!root.hasComment(commentBefore)) if (!root.hasComment(CommentPlacement::commentBefore))
return; return;
if (!indented_) if (!indented_)
writeIndent(); writeIndent();
const String& comment = root.getComment(commentBefore); const String& comment = root.getComment(CommentPlacement::commentBefore);
String::const_iterator iter = comment.begin(); String::const_iterator iter = comment.begin();
while (iter != comment.end()) { while (iter != comment.end()) {
*sout_ << *iter; *sout_ << *iter;
@ -1133,22 +1135,22 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine( void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(
Value const& root) { Value const& root) {
if (cs_ == CommentStyle::None) if (cs_ == CommentStyle::Enum::None)
return; return;
if (root.hasComment(commentAfterOnSameLine)) if (root.hasComment(CommentPlacement::commentAfterOnSameLine))
*sout_ << " " + root.getComment(commentAfterOnSameLine); *sout_ << " " + root.getComment(CommentPlacement::commentAfterOnSameLine);
if (root.hasComment(commentAfter)) { if (root.hasComment(CommentPlacement::commentAfter)) {
writeIndent(); writeIndent();
*sout_ << root.getComment(commentAfter); *sout_ << root.getComment(CommentPlacement::commentAfter);
} }
} }
// static // static
bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) { bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) {
return value.hasComment(commentBefore) || return value.hasComment(CommentPlacement::commentBefore) ||
value.hasComment(commentAfterOnSameLine) || value.hasComment(CommentPlacement::commentAfterOnSameLine) ||
value.hasComment(commentAfter); value.hasComment(CommentPlacement::commentAfter);
} }
/////////////// ///////////////
@ -1168,15 +1170,15 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const {
const bool usf = settings_["useSpecialFloats"].asBool(); const bool usf = settings_["useSpecialFloats"].asBool();
const bool emitUTF8 = settings_["emitUTF8"].asBool(); const bool emitUTF8 = settings_["emitUTF8"].asBool();
unsigned int pre = settings_["precision"].asUInt(); unsigned int pre = settings_["precision"].asUInt();
CommentStyle::Enum cs = CommentStyle::All; CommentStyle::Enum cs = CommentStyle::Enum::All;
if (cs_str == "All") { if (cs_str == "All") {
cs = CommentStyle::All; cs = CommentStyle::Enum::All;
} else if (cs_str == "None") { } else if (cs_str == "None") {
cs = CommentStyle::None; cs = CommentStyle::Enum::None;
} else { } else {
throwRuntimeError("commentStyle must be 'All' or 'None'"); throwRuntimeError("commentStyle must be 'All' or 'None'");
} }
PrecisionType precisionType(significantDigits); PrecisionType precisionType(PrecisionType::significantDigits);
if (pt_str == "significant") { if (pt_str == "significant") {
precisionType = PrecisionType::significantDigits; precisionType = PrecisionType::significantDigits;
} else if (pt_str == "decimal") { } else if (pt_str == "decimal") {