diff --git a/include/yaml-cpp/node/detail/node.h b/include/yaml-cpp/node/detail/node.h index 4d96b5c..fcd72da 100644 --- a/include/yaml-cpp/node/detail/node.h +++ b/include/yaml-cpp/node/detail/node.h @@ -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; + using nodes = std::set; nodes m_dependencies; }; } // namespace detail diff --git a/src/convert.cpp b/src/convert.cpp index ec05b77..0ab12b1 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -16,8 +16,8 @@ std::string tolower(const std::string& str) { template 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::decode(const Node& node, bool& rhs) { @@ -52,19 +52,22 @@ bool convert::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::decode(const Node& node, bool& rhs) { return false; } -} +} // namespace YAML diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp index e348599..3764c2b 100644 --- a/src/emitterutils.cpp +++ b/src/emitterutils.cpp @@ -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(str[i]))) { + for (char ch : str) { + if (escapeNonAscii && (0x80 <= static_cast(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(str[i]))) { + for (char ch : str) { + if (escapeNonAscii && (0x80 <= static_cast(ch))) { return false; } } diff --git a/src/exp.cpp b/src/exp.cpp index 695440a..5c3d471 100644 --- a/src/exp.cpp +++ b/src/exp.cpp @@ -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 diff --git a/src/ostream_wrapper.cpp b/src/ostream_wrapper.cpp index 2127dfe..047a9f7 100644 --- a/src/ostream_wrapper.cpp +++ b/src/ostream_wrapper.cpp @@ -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); } } diff --git a/src/regeximpl.h b/src/regeximpl.h index 709124f..a742cdc 100644 --- a/src/regeximpl.h +++ b/src/regeximpl.h @@ -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( 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 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 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 diff --git a/src/token.h b/src/token.h index 9a27f3d..9c9a5b7 100644 --- a/src/token.h +++ b/src/token.h @@ -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; }