replace find/rfind with startsWith

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent 761acafd69
commit 28d1880176

@ -6,6 +6,7 @@
#include "config.h"
#include "enforce.hpp"
#include "error.hpp"
#include "utils.hpp"
// + standard includes
#include <algorithm>
@ -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;

@ -11,6 +11,7 @@
#include "jpgimage.hpp"
#include "photoshop.hpp"
#include "safe_op.hpp"
#include "utils.hpp"
#ifdef _WIN32
#include <windows.h>
@ -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/.<x:
// 1787 | 0xe1 APP1 | 65460 | http://ns.adobe.com/xmp/extensio
if (option == kpsXMP && signature.rfind("http://ns.adobe.com/x", 0) == 0) {
if (option == kpsXMP && startsWith(signature, "http://ns.adobe.com/x")) {
// extract XMP
const char* xmp = buf.c_str();
size_t start = 2;

@ -7,6 +7,7 @@
#include "makernote_int.hpp"
#include "tags.hpp"
#include "types.hpp"
#include "utils.hpp"
#include "value.hpp"
#include <array>
@ -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;
}

@ -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;
}

@ -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<std::string> 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 {

Loading…
Cancel
Save