mirror of
https://github.com/nlohmann/json.git
synced 2026-09-29 19:20:30 +00:00
Address the clang-tidy findings of element access and iteration
Marks the default initializer of the item's index string (needed by GCC's -Weffc++) and, in the test, an escaped literal and a comparison of find() with end(), which is what the test is about. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -183,7 +183,7 @@ class view_item
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
iterator m_it;
|
iterator m_it;
|
||||||
std::string m_index{};
|
std::string m_index{}; // NOLINT(readability-redundant-member-init)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// the range returned by basic_json_view::items()
|
/// the range returned by basic_json_view::items()
|
||||||
|
|||||||
@@ -1933,7 +1933,7 @@ class view_item
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
iterator m_it;
|
iterator m_it;
|
||||||
std::string m_index{};
|
std::string m_index{}; // NOLINT(readability-redundant-member-init)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// the range returned by basic_json_view::items()
|
/// the range returned by basic_json_view::items()
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ TEST_CASE("json_view element access and iteration")
|
|||||||
std::vector<std::string> keys = {"", "x"};
|
std::vector<std::string> keys = {"", "x"};
|
||||||
for (std::size_t n = 1; n <= 40; ++n)
|
for (std::size_t n = 1; n <= 40; ++n)
|
||||||
{
|
{
|
||||||
keys.push_back(std::string(n, 'k'));
|
keys.emplace_back(n, 'k');
|
||||||
keys.push_back(std::string(n, 'k') + "x");
|
keys.push_back(std::string(n, 'k') + "x");
|
||||||
keys.push_back("x" + std::string(n, 'k'));
|
keys.push_back("x" + std::string(n, 'k'));
|
||||||
}
|
}
|
||||||
@@ -513,7 +513,7 @@ TEST_CASE("json_view element access and iteration")
|
|||||||
{
|
{
|
||||||
text += (i != 0 ? ",\"" : "\"") + keys[i] + "\":" + std::to_string(i);
|
text += (i != 0 ? ",\"" : "\"") + keys[i] + "\":" + std::to_string(i);
|
||||||
}
|
}
|
||||||
text += ",\"esc\\u0061ped\":\"escaped key\"}";
|
text += ",\"esc\\u0061ped\":\"escaped key\"}"; // NOLINT(modernize-raw-string-literal)
|
||||||
const json_document d = json_document::parse(text);
|
const json_document d = json_document::parse(text);
|
||||||
const json_view root = d.root();
|
const json_view root = d.root();
|
||||||
for (std::size_t i = 0; i < keys.size(); ++i)
|
for (std::size_t i = 0; i < keys.size(); ++i)
|
||||||
@@ -583,7 +583,7 @@ TEST_CASE("json_view element access and iteration")
|
|||||||
}
|
}
|
||||||
CHECK(v.contains("a") == j.contains("a"));
|
CHECK(v.contains("a") == j.contains("a"));
|
||||||
CHECK(v.count("a") == j.count("a"));
|
CHECK(v.count("a") == j.count("a"));
|
||||||
CHECK((v.find("a") == v.end()) == (j.find("a") == j.end()));
|
CHECK((v.find("a") == v.end()) == (j.find("a") == j.end())); // NOLINT(readability-container-contains): find() is what is tested
|
||||||
}
|
}
|
||||||
|
|
||||||
// where basic_json has undefined behavior, the view answers safely
|
// where basic_json has undefined behavior, the view answers safely
|
||||||
|
|||||||
Reference in New Issue
Block a user