mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-07 09:04:57 +02:00
STYLE: Use range-based loops from C++11
C++11 Range based for loops can be used in Used as a more readable equivalent to the traditional for loop operating over a range of values, such as all elements in a container, in the forward direction.. Range based loopes are more explicit for only computing the end location once for containers. SRCDIR=/Users/johnsonhj/src/jsoncpp/ #My local SRC BLDDIR=/Users/johnsonhj/src/jsoncpp/cmake-build-debug/ #My local BLD cd /Users/johnsonhj/src/jsoncpp/cmake-build-debug/ run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-loop-convert -header-filter=.* -fix
This commit is contained in:
parent
3beadff472
commit
cbeed7b076
@ -110,9 +110,7 @@ static void printValueTree(FILE* fout,
|
|||||||
Json::Value::Members members(value.getMemberNames());
|
Json::Value::Members members(value.getMemberNames());
|
||||||
std::sort(members.begin(), members.end());
|
std::sort(members.begin(), members.end());
|
||||||
JSONCPP_STRING suffix = *(path.end() - 1) == '.' ? "" : ".";
|
JSONCPP_STRING suffix = *(path.end() - 1) == '.' ? "" : ".";
|
||||||
for (Json::Value::Members::iterator it = members.begin();
|
for (auto name : members) {
|
||||||
it != members.end(); ++it) {
|
|
||||||
const JSONCPP_STRING name = *it;
|
|
||||||
printValueTree(fout, value[name], path + suffix + name);
|
printValueTree(fout, value[name], path + suffix + name);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
@ -818,9 +818,7 @@ JSONCPP_STRING Reader::getFormatedErrorMessages() const {
|
|||||||
|
|
||||||
JSONCPP_STRING Reader::getFormattedErrorMessages() const {
|
JSONCPP_STRING Reader::getFormattedErrorMessages() const {
|
||||||
JSONCPP_STRING formattedMessage;
|
JSONCPP_STRING formattedMessage;
|
||||||
for (Errors::const_iterator itError = errors_.begin();
|
for (const auto & error : errors_) {
|
||||||
itError != errors_.end(); ++itError) {
|
|
||||||
const ErrorInfo& error = *itError;
|
|
||||||
formattedMessage +=
|
formattedMessage +=
|
||||||
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
||||||
formattedMessage += " " + error.message_ + "\n";
|
formattedMessage += " " + error.message_ + "\n";
|
||||||
@ -833,9 +831,7 @@ JSONCPP_STRING Reader::getFormattedErrorMessages() const {
|
|||||||
|
|
||||||
std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
||||||
std::vector<Reader::StructuredError> allErrors;
|
std::vector<Reader::StructuredError> allErrors;
|
||||||
for (Errors::const_iterator itError = errors_.begin();
|
for (const auto & error : errors_) {
|
||||||
itError != errors_.end(); ++itError) {
|
|
||||||
const ErrorInfo& error = *itError;
|
|
||||||
Reader::StructuredError structured;
|
Reader::StructuredError structured;
|
||||||
structured.offset_start = error.token_.start_ - begin_;
|
structured.offset_start = error.token_.start_ - begin_;
|
||||||
structured.offset_limit = error.token_.end_ - begin_;
|
structured.offset_limit = error.token_.end_ - begin_;
|
||||||
@ -1833,9 +1829,7 @@ JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {
|
|||||||
|
|
||||||
JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
|
JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
|
||||||
JSONCPP_STRING formattedMessage;
|
JSONCPP_STRING formattedMessage;
|
||||||
for (Errors::const_iterator itError = errors_.begin();
|
for (const auto & error : errors_) {
|
||||||
itError != errors_.end(); ++itError) {
|
|
||||||
const ErrorInfo& error = *itError;
|
|
||||||
formattedMessage +=
|
formattedMessage +=
|
||||||
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
||||||
formattedMessage += " " + error.message_ + "\n";
|
formattedMessage += " " + error.message_ + "\n";
|
||||||
@ -1848,9 +1842,7 @@ JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
|
|||||||
|
|
||||||
std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
|
std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
|
||||||
std::vector<OurReader::StructuredError> allErrors;
|
std::vector<OurReader::StructuredError> allErrors;
|
||||||
for (Errors::const_iterator itError = errors_.begin();
|
for (const auto & error : errors_) {
|
||||||
itError != errors_.end(); ++itError) {
|
|
||||||
const ErrorInfo& error = *itError;
|
|
||||||
OurReader::StructuredError structured;
|
OurReader::StructuredError structured;
|
||||||
structured.offset_start = error.token_.start_ - begin_;
|
structured.offset_start = error.token_.start_ - begin_;
|
||||||
structured.offset_limit = error.token_.end_ - begin_;
|
structured.offset_limit = error.token_.end_ - begin_;
|
||||||
|
@ -1655,8 +1655,7 @@ void Path::invalidPath(const JSONCPP_STRING& /*path*/, int /*location*/) {
|
|||||||
|
|
||||||
const Value& Path::resolve(const Value& root) const {
|
const Value& Path::resolve(const Value& root) const {
|
||||||
const Value* node = &root;
|
const Value* node = &root;
|
||||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
for (const auto & arg : args_) {
|
||||||
const PathArgument& arg = *it;
|
|
||||||
if (arg.kind_ == PathArgument::kindIndex) {
|
if (arg.kind_ == PathArgument::kindIndex) {
|
||||||
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
|
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
|
||||||
// Error: unable to resolve path (array value expected at position...
|
// Error: unable to resolve path (array value expected at position...
|
||||||
@ -1681,8 +1680,7 @@ const Value& Path::resolve(const Value& root) const {
|
|||||||
|
|
||||||
Value Path::resolve(const Value& root, const Value& defaultValue) const {
|
Value Path::resolve(const Value& root, const Value& defaultValue) const {
|
||||||
const Value* node = &root;
|
const Value* node = &root;
|
||||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
for (const auto & arg : args_) {
|
||||||
const PathArgument& arg = *it;
|
|
||||||
if (arg.kind_ == PathArgument::kindIndex) {
|
if (arg.kind_ == PathArgument::kindIndex) {
|
||||||
if (!node->isArray() || !node->isValidIndex(arg.index_))
|
if (!node->isArray() || !node->isValidIndex(arg.index_))
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@ -1700,8 +1698,7 @@ Value Path::resolve(const Value& root, const Value& defaultValue) const {
|
|||||||
|
|
||||||
Value& Path::make(Value& root) const {
|
Value& Path::make(Value& root) const {
|
||||||
Value* node = &root;
|
Value* node = &root;
|
||||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
for (const auto & arg : args_) {
|
||||||
const PathArgument& arg = *it;
|
|
||||||
if (arg.kind_ == PathArgument::kindIndex) {
|
if (arg.kind_ == PathArgument::kindIndex) {
|
||||||
if (!node->isArray()) {
|
if (!node->isArray()) {
|
||||||
// Error: node is not an array at position ...
|
// Error: node is not an array at position ...
|
||||||
|
@ -150,9 +150,7 @@ void TestResult::printFailure(bool printTestName) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print in reverse to display the callstack in the right order
|
// Print in reverse to display the callstack in the right order
|
||||||
Failures::const_iterator itEnd = failures_.end();
|
for (const auto & failure : failures_ ) {
|
||||||
for (Failures::const_iterator it = failures_.begin(); it != itEnd; ++it) {
|
|
||||||
const Failure& failure = *it;
|
|
||||||
JSONCPP_STRING indent(failure.nestingLevel_ * 2, ' ');
|
JSONCPP_STRING indent(failure.nestingLevel_ * 2, ' ');
|
||||||
if (failure.file_) {
|
if (failure.file_) {
|
||||||
printf("%s%s(%u): ", indent.c_str(), failure.file_, failure.line_);
|
printf("%s%s(%u): ", indent.c_str(), failure.file_, failure.line_);
|
||||||
@ -275,8 +273,7 @@ bool Runner::runAllTest(bool printSummary) const {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (unsigned int index = 0; index < failures.size(); ++index) {
|
for (auto & result : failures) {
|
||||||
TestResult& result = failures[index];
|
|
||||||
result.printFailure(count > 1);
|
result.printFailure(count > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2365,8 +2365,7 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
|
|||||||
{ __LINE__, false, "{\"a\":.Infinity}" }, { __LINE__, false, "{\"a\":_Infinity}" },
|
{ __LINE__, false, "{\"a\":.Infinity}" }, { __LINE__, false, "{\"a\":_Infinity}" },
|
||||||
{ __LINE__, false, "{\"a\":_nfinity}" }, { __LINE__, true, "{\"a\":-Infinity}" }
|
{ __LINE__, false, "{\"a\":_nfinity}" }, { __LINE__, true, "{\"a\":-Infinity}" }
|
||||||
};
|
};
|
||||||
for (size_t tdi = 0; tdi < sizeof(test_data) / sizeof(*test_data); ++tdi) {
|
for (const auto& td : test_data) {
|
||||||
const TestData& td = test_data[tdi];
|
|
||||||
bool ok = reader->parse(&*td.in.begin(), &*td.in.begin() + td.in.size(),
|
bool ok = reader->parse(&*td.in.begin(), &*td.in.begin() + td.in.size(),
|
||||||
&root, &errs);
|
&root, &errs);
|
||||||
JSONTEST_ASSERT(td.ok == ok) << "line:" << td.line << "\n"
|
JSONTEST_ASSERT(td.ok == ok) << "line:" << td.line << "\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user