aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-30 19:23:18 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-30 19:27:18 +0200
commit4f24617e1ea4ba7a6627a9c44304c6e0a0114249 (patch)
tree65c02e9e31cac60bac6f6aec165e8397dcde70e2 /libtests
parent7f023701dd843749cf878baabeb3d33917fda62f (diff)
downloadqpdf-4f24617e1ea4ba7a6627a9c44304c6e0a0114249.tar.zst
Code clean up: use range-style for loops wherever possible
Where not possible, use "auto" to get the iterator type. Editorial note: I have avoid this change for a long time because of not wanting to make gratuitous changes to version history, which can obscure when certain changes were made, but with having recently touched every single file to apply automatic code formatting and with making several broad changes to the API, I decided it was time to take the plunge and get rid of the older (pre-C++11) verbose iterator syntax. The new code is just easier to read and understand, and in many cases, it will be more effecient as fewer temporary copies are being made. m-holger, if you're reading, you can see that I've finally come around. :-)
Diffstat (limited to 'libtests')
-rw-r--r--libtests/json.cc6
-rw-r--r--libtests/numrange.cc6
-rw-r--r--libtests/qutil.cc17
3 files changed, 10 insertions, 19 deletions
diff --git a/libtests/json.cc b/libtests/json.cc
index 17a5d574..43f2b3c6 100644
--- a/libtests/json.cc
+++ b/libtests/json.cc
@@ -130,10 +130,8 @@ check_schema(
std::list<std::string> errors;
std::cout << "--- " << description << std::endl;
assert(exp == obj.checkSchema(schema, flags, errors));
- for (std::list<std::string>::iterator iter = errors.begin();
- iter != errors.end();
- ++iter) {
- std::cout << *iter << std::endl;
+ for (auto const& error: errors) {
+ std::cout << error << std::endl;
}
std::cout << "---" << std::endl;
}
diff --git a/libtests/numrange.cc b/libtests/numrange.cc
index d1548fe9..c0bf5bd7 100644
--- a/libtests/numrange.cc
+++ b/libtests/numrange.cc
@@ -9,10 +9,8 @@ test_numrange(char const* range)
} else {
std::vector<int> result = QUtil::parse_numrange(range, 15);
std::cout << "numeric range " << range << " ->";
- for (std::vector<int>::iterator iter = result.begin();
- iter != result.end();
- ++iter) {
- std::cout << " " << *iter;
+ for (int i: result) {
+ std::cout << " " << i;
}
std::cout << std::endl;
}
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index eb16bf0b..017f371b 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -229,12 +229,10 @@ print_utf8(unsigned long val)
// Emacs has trouble with utf-8 encoding files with characters
// outside the 16-bit portion, so just show the character
// values.
- for (std::string::iterator iter = result.begin(); iter != result.end();
- ++iter) {
+ for (auto const& ch: result) {
std::cout << " "
<< QUtil::int_to_string_base(
- static_cast<int>(
- static_cast<unsigned char>(*iter)),
+ static_cast<int>(static_cast<unsigned char>(ch)),
16,
2);
}
@@ -289,11 +287,10 @@ print_utf16(unsigned long val)
{
std::string result = QUtil::toUTF16(val);
std::cout << "0x" << QUtil::uint_to_string_base(val, 16) << " ->";
- for (std::string::iterator iter = result.begin(); iter != result.end();
- ++iter) {
+ for (auto const& ch: result) {
std::cout << " "
<< QUtil::int_to_string_base(
- static_cast<int>(static_cast<unsigned char>(*iter)),
+ static_cast<int>(static_cast<unsigned char>(ch)),
16,
2);
}
@@ -516,10 +513,8 @@ void
read_from_file_test()
{
std::list<std::string> lines = QUtil::read_lines_from_file("other-file");
- for (std::list<std::string>::iterator iter = lines.begin();
- iter != lines.end();
- ++iter) {
- std::cout << *iter << std::endl;
+ for (auto const& line: lines) {
+ std::cout << line << std::endl;
}
// Test the other versions and make sure we get the same results
{