Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace find/rfind with startsWith #2396

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "config.h"
#include "enforce.hpp"
#include "error.hpp"
#include "utils.hpp"

// + standard includes
#include <algorithm>
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "jpgimage.hpp"
#include "photoshop.hpp"
#include "safe_op.hpp"
#include "utils.hpp"

#ifdef _WIN32
#include <windows.h>
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/pentaxmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "makernote_int.hpp"
#include "tags.hpp"
#include "types.hpp"
#include "utils.hpp"
#include "value.hpp"

#include <array>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sonymn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/xmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "error.hpp"
#include "properties.hpp"
#include "types.hpp"
#include "utils.hpp"
#include "value.hpp"
#include "xmp_exiv2.hpp"

Expand Down Expand Up @@ -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 {
Expand Down