diff --git a/examples/pdf-mod-info.cc b/examples/pdf-mod-info.cc index e97fab9..c9fffa6 100644 --- a/examples/pdf-mod-info.cc +++ b/examples/pdf-mod-info.cc @@ -90,11 +90,11 @@ main(int argc, char* argv[]) } else if ((!strcmp(argv[i], "--key")) && (++i < argc)) { QTC::TC("examples", "pdf-mod-info -key"); cur_key = argv[i]; - if (!((cur_key.length() > 0) && (cur_key.at(0) == '/'))) { + if (cur_key.empty() || cur_key.at(0) != '/') { cur_key = "/" + cur_key; } Keys[cur_key] = ""; - } else if ((!strcmp(argv[i], "--val")) && (++i < argc)) { + } else if (!strcmp(argv[i], "--val") && ++i < argc) { if (cur_key.empty()) { QTC::TC("examples", "pdf-mod-info usage wrong val"); usage(); @@ -115,7 +115,7 @@ main(int argc, char* argv[]) QTC::TC("examples", "pdf-mod-info in-place"); fl_out = fl_in; } - if (Keys.size() == 0) { + if (Keys.empty()) { QTC::TC("examples", "pdf-mod-info no keys"); usage(); } @@ -141,7 +141,7 @@ main(int argc, char* argv[]) filetrailer.replaceKey("/Info", fileinfo); } } - if (it.second == "") { + if (it.second.empty()) { fileinfo.removeKey(it.first); } else { QPDFObjectHandle elt = fileinfo.newString(it.second); diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 46e87c9..5c513c3 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -675,7 +675,7 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( resources.mergeResources(merge_with, &dr_map); // Remove empty subdictionaries for (auto iter: resources.ditems()) { - if (iter.second.isDictionary() && (iter.second.getKeys().size() == 0)) { + if (iter.second.isDictionary() && iter.second.getKeys().empty()) { resources.removeKey(iter.first); } } diff --git a/libqpdf/QPDFArgParser.cc b/libqpdf/QPDFArgParser.cc index 08e727c..e1cdfe8 100644 --- a/libqpdf/QPDFArgParser.cc +++ b/libqpdf/QPDFArgParser.cc @@ -471,7 +471,7 @@ QPDFArgParser::parseArgs() // positional arguments. Besides, it doesn't make sense to have an empty option. arg_s = arg; size_t equal_pos = std::string::npos; - if (arg_s.length() > 0) { + if (!arg_s.empty()) { equal_pos = arg_s.find('=', 1); } if (equal_pos != std::string::npos) { @@ -686,7 +686,7 @@ QPDFArgParser::addHelpTopic( QTC::TC("libtests", "QPDFArgParser add reserved help topic"); throw std::logic_error("QPDFArgParser: can't register reserved help topic " + topic); } - if (!((topic.length() > 0) && (topic.at(0) != '-'))) { + if (topic.empty() || topic.at(0) == '-') { QTC::TC("libtests", "QPDFArgParser bad topic for help"); throw std::logic_error("QPDFArgParser: help topics must not start with -"); } diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 1a74ea4..9f762d7 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -396,7 +396,7 @@ QPDFJob::parseRotationParameter(std::string const& parameter) } else { angle_str = parameter; } - if (angle_str.length() > 0) { + if (!angle_str.empty()) { char first = angle_str.at(0); if ((first == '+') || (first == '-')) { relative = ((first == '+') ? 1 : -1); diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index 2aff98c..2eca88e 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -696,7 +696,7 @@ QPDFJob::Config::passwordFile(std::string const& parameter) QTC::TC("qpdf", "QPDFJob_config password file"); lines = QUtil::read_lines_from_file(parameter.c_str()); } - if (lines.size() >= 1) { + if (!lines.empty()) { o.m->password = QUtil::make_shared_cstr(lines.front()); if (lines.size() > 1) { diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index fba9cbc..f0baa22 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -467,7 +467,7 @@ BaseHandle::write_json(int json_version, JSON::Writer& p) const case ::ot_real: { auto const& val = std::get(obj->value).val; - if (val.length() == 0) { + if (val.empty()) { // Can't really happen... p << "0"; } else if (val.at(0) == '.') { diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index de7227d..4802543 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -271,7 +271,7 @@ void QPDFWriter::setExtraHeaderText(std::string const& text) { m->extra_header_text = text; - if ((m->extra_header_text.length() > 0) && (*(m->extra_header_text.rbegin()) != '\n')) { + if (!m->extra_header_text.empty() && *m->extra_header_text.rbegin() != '\n') { QTC::TC("qpdf", "QPDFWriter extra header text add newline"); m->extra_header_text += "\n"; } else { @@ -1419,7 +1419,7 @@ QPDFWriter::unparseObject( have_extensions_adbe = true; keys.erase("/ADBE"); } - if (keys.size() > 0) { + if (!keys.empty()) { have_extensions_other = true; } } diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 14f6693..3c3d86b 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -192,7 +192,7 @@ QPDF::test_json_validators() check(is_unicode_string("u:potato", str)); check(str == "potato"); check(is_unicode_string("u:", str)); - check(str == ""); + check(str.empty()); check(!is_binary_string("", str)); check(!is_binary_string("x:", str)); check(!is_binary_string("b:1", str)); diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index 12ad916..3e1f08c 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -153,7 +153,7 @@ QPDF::parse(char const* password) initializeEncryption(); m->parsed = true; - if (m->xref_table.size() > 0 && !getRoot().getKey("/Pages").isDictionary()) { + if (!m->xref_table.empty() && !getRoot().getKey("/Pages").isDictionary()) { // QPDFs created from JSON have an empty xref table and no root object yet. throw damagedPDF("", -1, "unable to find page tree"); } @@ -1932,8 +1932,8 @@ QPDF::tableSize() { // If obj_cache is dense, accommodate all object in tables,else accommodate only original // objects. - auto max_xref = m->xref_table.size() ? m->xref_table.crbegin()->first.getObj() : 0; - auto max_obj = m->obj_cache.size() ? m->obj_cache.crbegin()->first.getObj() : 0; + auto max_xref = !m->xref_table.empty() ? m->xref_table.crbegin()->first.getObj() : 0; + auto max_obj = !m->obj_cache.empty() ? m->obj_cache.crbegin()->first.getObj() : 0; auto max_id = std::numeric_limits::max() - 1; if (max_obj >= max_id || max_xref >= max_id) { // Temporary fix. Long-term solution is diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 14cf65f..445a38f 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -1442,7 +1442,7 @@ test_42(QPDF& pdf, char const* arg2) assert(i == di.end()); assert(!i_value.second); } - assert("" == qtest.getStringValue()); + assert(qtest.getStringValue().empty()); array.getArrayItem(-1).assertNull(); array.getArrayItem(16059).assertNull(); integer.getArrayItem(0).assertNull(); @@ -3111,7 +3111,7 @@ test_87(QPDF& pdf, char const* arg2) assert(dict.getKeys() == std::set({"/A"})); dict.replaceKey("/A", QPDFObjectHandle::newNull()); assert(dict.unparse() == "<< >>"); - assert(dict.getKeys() == std::set()); + assert(dict.getKeys().empty()); dict = QPDFObjectHandle::newDictionary({ {"/A", "2"_qpdf}, {"/B", QPDFObjectHandle::newNull()}, diff --git a/qpdf/test_parsedoffset.cc b/qpdf/test_parsedoffset.cc index f2b13b6..4721e12 100644 --- a/qpdf/test_parsedoffset.cc +++ b/qpdf/test_parsedoffset.cc @@ -120,7 +120,7 @@ main(int argc, char* argv[]) process(argv[1], table); for (size_t i = 0; i < table.size(); ++i) { - if (table[i].size() == 0) { + if (table[i].empty()) { continue; }