mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Modernize: Use range-based for loops for readability (#762)
Also run clang-format on these files as requested
This commit is contained in:

committed by
Jesse Beder

parent
21d75fa4cd
commit
b650bc8287
@@ -42,9 +42,8 @@ class node {
|
||||
return;
|
||||
|
||||
m_pRef->mark_defined();
|
||||
for (nodes::iterator it = m_dependencies.begin();
|
||||
it != m_dependencies.end(); ++it)
|
||||
(*it)->mark_defined();
|
||||
for (node* dependency : m_dependencies)
|
||||
dependency->mark_defined();
|
||||
m_dependencies.clear();
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ class node {
|
||||
|
||||
private:
|
||||
shared_node_ref m_pRef;
|
||||
using nodes = std::set<node *>;
|
||||
using nodes = std::set<node*>;
|
||||
nodes m_dependencies;
|
||||
};
|
||||
} // namespace detail
|
||||
|
@@ -16,8 +16,8 @@ std::string tolower(const std::string& str) {
|
||||
|
||||
template <typename T>
|
||||
bool IsEntirely(const std::string& str, T func) {
|
||||
for (std::size_t i = 0; i < str.size(); i++)
|
||||
if (!func(str[i]))
|
||||
for (char ch : str)
|
||||
if (!func(ch))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -39,7 +39,7 @@ bool IsFlexibleCase(const std::string& str) {
|
||||
std::string rest = str.substr(1);
|
||||
return firstcaps && (IsEntirely(rest, IsLower) || IsEntirely(rest, IsUpper));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace YAML {
|
||||
bool convert<bool>::decode(const Node& node, bool& rhs) {
|
||||
@@ -52,19 +52,22 @@ bool convert<bool>::decode(const Node& node, bool& rhs) {
|
||||
static const struct {
|
||||
std::string truename, falsename;
|
||||
} names[] = {
|
||||
{"y", "n"}, {"yes", "no"}, {"true", "false"}, {"on", "off"},
|
||||
{"y", "n"},
|
||||
{"yes", "no"},
|
||||
{"true", "false"},
|
||||
{"on", "off"},
|
||||
};
|
||||
|
||||
if (!IsFlexibleCase(node.Scalar()))
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
|
||||
if (names[i].truename == tolower(node.Scalar())) {
|
||||
for (const auto& name : names) {
|
||||
if (name.truename == tolower(node.Scalar())) {
|
||||
rhs = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (names[i].falsename == tolower(node.Scalar())) {
|
||||
if (name.falsename == tolower(node.Scalar())) {
|
||||
rhs = false;
|
||||
return true;
|
||||
}
|
||||
@@ -72,4 +75,4 @@ bool convert<bool>::decode(const Node& node, bool& rhs) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
@@ -199,11 +199,11 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
|
||||
|
||||
bool IsValidSingleQuotedScalar(const std::string& str, bool escapeNonAscii) {
|
||||
// TODO: check for non-printable characters?
|
||||
for (std::size_t i = 0; i < str.size(); i++) {
|
||||
if (escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i]))) {
|
||||
for (char ch : str) {
|
||||
if (escapeNonAscii && (0x80 <= static_cast<unsigned char>(ch))) {
|
||||
return false;
|
||||
}
|
||||
if (str[i] == '\n') {
|
||||
if (ch == '\n') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -217,8 +217,8 @@ bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType,
|
||||
}
|
||||
|
||||
// TODO: check for non-printable characters?
|
||||
for (std::size_t i = 0; i < str.size(); i++) {
|
||||
if (escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i]))) {
|
||||
for (char ch : str) {
|
||||
if (escapeNonAscii && (0x80 <= static_cast<unsigned char>(ch))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -12,8 +12,7 @@ namespace YAML {
|
||||
namespace Exp {
|
||||
unsigned ParseHex(const std::string& str, const Mark& mark) {
|
||||
unsigned value = 0;
|
||||
for (std::size_t i = 0; i < str.size(); i++) {
|
||||
char ch = str[i];
|
||||
for (char ch : str) {
|
||||
int digit = 0;
|
||||
if ('a' <= ch && ch <= 'f')
|
||||
digit = ch - 'a' + 10;
|
||||
@@ -132,5 +131,5 @@ std::string Escape(Stream& in) {
|
||||
std::stringstream msg;
|
||||
throw ParserException(in.mark(), std::string(ErrorMsg::INVALID_ESCAPE) + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Exp
|
||||
} // namespace YAML
|
||||
|
@@ -31,8 +31,8 @@ void ostream_wrapper::write(const std::string& str) {
|
||||
std::copy(str.begin(), str.end(), m_buffer.begin() + m_pos);
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < str.size(); i++) {
|
||||
update_pos(str[i]);
|
||||
for (char ch : str) {
|
||||
update_pos(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8,8 +8,8 @@
|
||||
#endif
|
||||
|
||||
#include "stream.h"
|
||||
#include "stringsource.h"
|
||||
#include "streamcharsource.h"
|
||||
#include "stringsource.h"
|
||||
|
||||
namespace YAML {
|
||||
// query matches
|
||||
@@ -106,9 +106,8 @@ inline int RegEx::MatchOpEmpty(const Source& source) const {
|
||||
template <>
|
||||
inline int RegEx::MatchOpEmpty<StringCharSource>(
|
||||
const StringCharSource& source) const {
|
||||
return !source
|
||||
? 0
|
||||
: -1; // the empty regex only is successful on the empty string
|
||||
return !source ? 0 : -1; // the empty regex only is successful on the empty
|
||||
// string
|
||||
}
|
||||
|
||||
// MatchOperator
|
||||
@@ -130,8 +129,8 @@ inline int RegEx::MatchOpRange(const Source& source) const {
|
||||
// OrOperator
|
||||
template <typename Source>
|
||||
inline int RegEx::MatchOpOr(const Source& source) const {
|
||||
for (std::size_t i = 0; i < m_params.size(); i++) {
|
||||
int n = m_params[i].MatchUnchecked(source);
|
||||
for (const RegEx& param : m_params) {
|
||||
int n = param.MatchUnchecked(source);
|
||||
if (n >= 0)
|
||||
return n;
|
||||
}
|
||||
@@ -169,11 +168,11 @@ inline int RegEx::MatchOpNot(const Source& source) const {
|
||||
template <typename Source>
|
||||
inline int RegEx::MatchOpSeq(const Source& source) const {
|
||||
int offset = 0;
|
||||
for (std::size_t i = 0; i < m_params.size(); i++) {
|
||||
int n = m_params[i].Match(source + offset); // note Match, not
|
||||
// MatchUnchecked because we
|
||||
// need to check validity after
|
||||
// the offset
|
||||
for (const RegEx& param : m_params) {
|
||||
int n = param.Match(source + offset); // note Match, not
|
||||
// MatchUnchecked because we
|
||||
// need to check validity after
|
||||
// the offset
|
||||
if (n == -1)
|
||||
return -1;
|
||||
offset += n;
|
||||
@@ -181,6 +180,6 @@ inline int RegEx::MatchOpSeq(const Source& source) const {
|
||||
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
#endif // REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@@ -53,8 +53,8 @@ struct Token {
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const Token& token) {
|
||||
out << TokenNames[token.type] << std::string(": ") << token.value;
|
||||
for (std::size_t i = 0; i < token.params.size(); i++)
|
||||
out << std::string(" ") << token.params[i];
|
||||
for (const std::string& param : token.params)
|
||||
out << std::string(" ") << param;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user