From 28d18801767f2cba76a21bf8cb22f67d35cde6a1 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 4 Oct 2022 00:43:26 -0700 Subject: [PATCH] replace find/rfind with startsWith Signed-off-by: Rosen Penev --- src/futils.cpp | 3 ++- src/jpgimage.cpp | 4 +++- src/pentaxmn_int.cpp | 9 +++++---- src/sonymn_int.cpp | 2 +- src/xmp.cpp | 3 ++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/futils.cpp b/src/futils.cpp index 720c1790..380c5386 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -6,6 +6,7 @@ #include "config.h" #include "enforce.hpp" #include "error.hpp" +#include "utils.hpp" // + standard includes #include @@ -205,7 +206,7 @@ Protocol fileProtocol(const std::string& path) { if (result != pFile) break; - if (path.rfind(prot.name, 0) == 0) + if (Exiv2::Internal::startsWith(path, prot.name)) // URL's require data. Stdin == "-" and no further data if (prot.isUrl ? path.size() > prot.name.size() : path.size() == prot.name.size()) result = prot.prot; diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index dabc72c7..5f8d0e0e 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -11,6 +11,7 @@ #include "jpgimage.hpp" #include "photoshop.hpp" #include "safe_op.hpp" +#include "utils.hpp" #ifdef _WIN32 #include @@ -30,6 +31,7 @@ namespace Exiv2 { +using Exiv2::Internal::startsWith; namespace { // JPEG Segment markers (The first byte is always 0xFF, the value of these constants correspond to the 2nd byte) constexpr byte sos_ = 0xda; //!< JPEG SOS marker @@ -371,7 +373,7 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, si // 2 | 0xe1 APP1 | 911 | Exif..MM.*.......%.........#.... // 915 | 0xe1 APP1 | 870 | http://ns.adobe.com/xap/1.0/. @@ -1178,7 +1179,7 @@ std::ostream& resolveLens0x8ff(std::ostream& os, const Value& value, const ExifD const auto lensInfo = findLensInfo(metadata); if (value.count() == 4) { std::string model = getKeyString("Exif.Image.Model", metadata); - if (model.rfind("PENTAX K-3", 0) == 0 && lensInfo->count() == 128 && lensInfo->toUint32(1) == 168 && + if (startsWith(model, "PENTAX K-3") && lensInfo->count() == 128 && lensInfo->toUint32(1) == 168 && lensInfo->toUint32(2) == 144) index = 7; } @@ -1205,15 +1206,15 @@ std::ostream& resolveLens0x319(std::ostream& os, const Value& value, const ExifD const auto lensInfo = findLensInfo(metadata); if (value.count() == 4) { std::string model = getKeyString("Exif.Image.Model", metadata); - if (model.rfind("PENTAX K-3", 0) == 0 && lensInfo->count() == 128 && lensInfo->toUint32(1) == 131 && + if (startsWith(model, "PENTAX K-3") && lensInfo->count() == 128 && lensInfo->toUint32(1) == 131 && lensInfo->toUint32(2) == 128) index = 6; } if (value.count() == 2) { std::string model = getKeyString("Exif.Image.Model", metadata); - if (model.rfind("PENTAX K100D", 0) == 0 && lensInfo->count() == 44) + if (startsWith(model, "PENTAX K100D") && lensInfo->count() == 44) index = 6; - if (model.rfind("PENTAX *ist DL", 0) == 0 && lensInfo->count() == 36) + if (startsWith(model, "PENTAX *ist DL") && lensInfo->count() == 36) index = 6; } diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index c7616bc3..ef90c787 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -1862,7 +1862,7 @@ std::ostream& SonyMakerNote::printSony2FpFocusPosition2(std::ostream& os, const // Ranges of models that do not support this tag for (auto& m : {"DSC-", "Stellar"}) { - if (model.find(m) == 0) { + if (startsWith(model, m)) { os << N_("n/a"); return os; } diff --git a/src/xmp.cpp b/src/xmp.cpp index 8dd91bf5..db3e253b 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -4,6 +4,7 @@ #include "error.hpp" #include "properties.hpp" #include "types.hpp" +#include "utils.hpp" #include "value.hpp" #include "xmp_exiv2.hpp" @@ -494,7 +495,7 @@ void XmpData::eraseFamily(XmpData::iterator& pos) { std::string key(pos->key()); std::vector keys; while (pos != xmpMetadata_.end()) { - if (pos->key().find(key) == 0) { + if (Exiv2::Internal::startsWith(pos->key(), key)) { keys.push_back(pos->key()); pos++; } else {