From e74feff4d804c45ef7ab6a4a0e11a767900d2725 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 2 Aug 2022 00:27:58 -0700 Subject: [PATCH] strcmp to == conversions Does the same thing. Signed-off-by: Rosen Penev --- app/actions.cpp | 2 +- app/exiv2.cpp | 2 +- src/datasets.cpp | 3 +-- src/easyaccess.cpp | 4 ++-- src/properties.cpp | 22 ++++++++-------------- src/tags.cpp | 5 ++--- src/tiffcomposite_int.cpp | 4 ++-- src/tiffvisitor_int.cpp | 6 +++--- src/types.cpp | 2 +- 9 files changed, 21 insertions(+), 29 deletions(-) diff --git a/app/actions.cpp b/app/actions.cpp index 430a9bb4..698f74df 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -1475,7 +1475,7 @@ int FixIso::run(const std::string& path) { } auto md = Exiv2::isoSpeed(exifData); if (md != exifData.end()) { - if (strcmp(md->key().c_str(), "Exif.Photo.ISOSpeedRatings") == 0) { + if (md->key() == "Exif.Photo.ISOSpeedRatings") { if (Params::instance().verbose_) { std::cout << _("Standard Exif ISO tag exists; not modified\n"); } diff --git a/app/exiv2.cpp b/app/exiv2.cpp index 063c5332..08c8a665 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -1182,7 +1182,7 @@ int64_t parseCommonTargets(const std::string& optArg, const std::string& action) break; case 'p': { - if (strcmp(action.c_str(), "extract") == 0) { + if (action == "extract") { i += static_cast( parsePreviewNumbers(Params::instance().previewNumbers_, optArg, static_cast(i) + 1)); target |= Params::ctPreview; diff --git a/src/datasets.cpp b/src/datasets.cpp index 5cb5807b..8bfd0f84 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -568,9 +568,8 @@ void IptcKey::decomposeKey() { auto posDot2 = key_.find('.', posDot1 + 1); const std::string familyName = key_.substr(0, posDot1); - if (0 != strcmp(familyName.c_str(), familyName_)) { + if (familyName != familyName_) throw Error(ErrorCode::kerInvalidKey, key_); - } std::string recordName = key_.substr(posDot1 + 1, posDot2 - posDot1 - 1); std::string dataSetName = key_.substr(posDot2 + 1); diff --git a/src/easyaccess.cpp b/src/easyaccess.cpp index dd83bcdd..425fa83b 100644 --- a/src/easyaccess.cpp +++ b/src/easyaccess.cpp @@ -100,7 +100,7 @@ ExifData::const_iterator isoSpeed(const ExifData& ed) { iso_val = parseInt64(os.str(), ok); if (ok && iso_val > 0) break; - while (strcmp(keys[idx++], md->key().c_str()) != 0 && idx < cnt) { + while (md->key() != keys[idx++] && idx < cnt) { } md = ed.end(); } @@ -139,7 +139,7 @@ ExifData::const_iterator isoSpeed(const ExifData& ed) { md = md_st; break; } - while (strcmp(sensKeys->keys[idx++], md_st->key().c_str()) != 0 && idx < sensKeys->count) { + while (md_st->key() != sensKeys->keys[idx++] && idx < sensKeys->count) { } } break; diff --git a/src/properties.cpp b/src/properties.cpp index 1258a2c6..d6df9eb0 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -18,7 +18,7 @@ namespace { struct XmpPrintInfo { //! Comparison operator for key bool operator==(const std::string& key) const { - return 0 == strcmp(key_, key.c_str()); + return key == key_; } const char* key_; //!< XMP key @@ -4889,9 +4889,8 @@ void XmpProperties::registerNs(const std::string& ns, const std::string& prefix) const XmpNsInfo* xnp = lookupNsRegistryUnsafe(XmpNsInfo::Prefix(prefix)); if (xnp) { #ifndef SUPPRESS_WARNINGS - if (strcmp(xnp->ns_, ns2.c_str()) != 0) { + if (ns2 != xnp->ns_) EXV_WARNING << "Updating namespace URI for " << prefix << " from " << xnp->ns_ << " to " << ns2 << "\n"; - } #endif unregisterNsUnsafe(xnp->ns_); } @@ -4998,7 +4997,7 @@ const XmpPropertyInfo* XmpProperties::propertyInfo(const XmpKey& key) { return nullptr; const XmpPropertyInfo* pi = nullptr; for (int j = 0; pl[j].name_; ++j) { - if (0 == strcmp(pl[j].name_, property.c_str())) { + if (property == pl[j].name_) { pi = pl + j; break; } @@ -5158,26 +5157,21 @@ std::string XmpKey::ns() const { void XmpKey::Impl::decomposeKey(const std::string& key) { // Get the family name, prefix and property name parts of the key std::string::size_type pos1 = key.find('.'); - if (pos1 == std::string::npos) { + if (pos1 == std::string::npos) throw Error(ErrorCode::kerInvalidKey, key); - } std::string familyName = key.substr(0, pos1); - if (0 != strcmp(familyName.c_str(), familyName_)) { + if (familyName != familyName_) throw Error(ErrorCode::kerInvalidKey, key); - } std::string::size_type pos0 = pos1 + 1; pos1 = key.find('.', pos0); - if (pos1 == std::string::npos) { + if (pos1 == std::string::npos) throw Error(ErrorCode::kerInvalidKey, key); - } std::string prefix = key.substr(pos0, pos1 - pos0); - if (prefix.empty()) { + if (prefix.empty()) throw Error(ErrorCode::kerInvalidKey, key); - } std::string property = key.substr(pos1 + 1); - if (property.empty()) { + if (property.empty()) throw Error(ErrorCode::kerInvalidKey, key); - } // Validate prefix if (XmpProperties::ns(prefix).empty()) diff --git a/src/tags.cpp b/src/tags.cpp index 63896846..162f6177 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -77,7 +77,7 @@ bool GroupInfo::operator==(IfdId ifdId) const { } bool GroupInfo::operator==(const GroupName& groupName) const { - return 0 == strcmp(groupName.g_.c_str(), groupName_); + return groupName.g_ == groupName_; } const char* ExifTags::sectionName(const ExifKey& key) { @@ -198,9 +198,8 @@ void ExifKey::Impl::decomposeKey(const std::string& key) { if (pos1 == std::string::npos) throw Error(ErrorCode::kerInvalidKey, key); std::string familyName = key.substr(0, pos1); - if (0 != strcmp(familyName.c_str(), familyName_)) { + if (familyName != familyName_) throw Error(ErrorCode::kerInvalidKey, key); - } std::string::size_type pos0 = pos1 + 1; pos1 = key.find('.', pos0); if (pos1 == std::string::npos) diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 1b96a9ea..4a5be65f 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -24,8 +24,8 @@ uint32_t fillGap(Exiv2::Internal::IoWrapper& ioWrapper, uint32_t curr, uint32_t // class member definitions namespace Exiv2::Internal { bool TiffMappingInfo::operator==(const TiffMappingInfo::Key& key) const { - return (0 == strcmp("*", make_) || 0 == strncmp(make_, key.m_.c_str(), strlen(make_))) && - (Tag::all == extendedTag_ || key.e_ == extendedTag_) && key.g_ == group_; + return (0 == strcmp("*", make_) || key.m_ == make_) && (Tag::all == extendedTag_ || key.e_ == extendedTag_) && + key.g_ == group_; } IoWrapper::IoWrapper(BasicIo& io, const byte* pHeader, size_t size, OffsetWriter* pow) : diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 5f4a096f..8335f1ae 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -27,7 +27,7 @@ class FindExifdatum2 { } //! Returns true if group and index match. bool operator()(const Exiv2::Exifdatum& md) const { - return idx_ == md.idx() && 0 == strcmp(md.groupName().c_str(), groupName_); + return idx_ == md.idx() && md.groupName() == groupName_; } private: @@ -38,9 +38,9 @@ class FindExifdatum2 { Exiv2::ByteOrder stringToByteOrder(const std::string& val) { Exiv2::ByteOrder bo = Exiv2::invalidByteOrder; - if (0 == strcmp("II", val.c_str())) + if (val == "II") bo = Exiv2::littleEndian; - else if (0 == strcmp("MM", val.c_str())) + else if (val == "MM") bo = Exiv2::bigEndian; return bo; diff --git a/src/types.cpp b/src/types.cpp index adb97bac..34d46613 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -31,7 +31,7 @@ struct TypeInfoTable { } //! Comparison operator for \em name bool operator==(const std::string& name) const { - return 0 == strcmp(name_, name.c_str()); + return name == name_; } }; // struct TypeInfoTable