add contains function
Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
28358cd209
commit
9f21b78311
@ -10,6 +10,7 @@
|
|||||||
#include "convert.hpp"
|
#include "convert.hpp"
|
||||||
#include "getopt.hpp"
|
#include "getopt.hpp"
|
||||||
#include "i18n.h" // NLS support.
|
#include "i18n.h" // NLS support.
|
||||||
|
#include "utils.hpp"
|
||||||
#include "xmp_exiv2.hpp"
|
#include "xmp_exiv2.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -1119,7 +1120,7 @@ bool parseTime(const std::string& ts, int64_t& time) {
|
|||||||
hh *= -1;
|
hh *= -1;
|
||||||
}
|
}
|
||||||
// check for the -0 special case
|
// check for the -0 special case
|
||||||
if (hh == 0 && hstr.find('-') != std::string::npos)
|
if (hh == 0 && Exiv2::Internal::contains(hstr, '-'))
|
||||||
sign = -1;
|
sign = -1;
|
||||||
// MM part, if there is one
|
// MM part, if there is one
|
||||||
if (!mstr.empty()) {
|
if (!mstr.empty()) {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include "tiffimage.hpp"
|
#include "tiffimage.hpp"
|
||||||
#include "tiffimage_int.hpp"
|
#include "tiffimage_int.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
#ifdef EXV_HAVE_BROTLI
|
#ifdef EXV_HAVE_BROTLI
|
||||||
#include <brotli/decode.h> // for JXL brob
|
#include <brotli/decode.h> // for JXL brob
|
||||||
@ -349,11 +350,10 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
|
|||||||
const size_t maxlen = data.size() - skip;
|
const size_t maxlen = data.size() - skip;
|
||||||
Internal::enforce(maxlen > 0 && strnlen(str, maxlen) < maxlen, Exiv2::ErrorCode::kerCorruptedMetadata);
|
Internal::enforce(maxlen > 0 && strnlen(str, maxlen) < maxlen, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
std::string name(str);
|
std::string name(str);
|
||||||
if (name.find("Exif") != std::string::npos) { // "Exif" or "ExifExif"
|
if (Internal::contains(name, "Exif")) { // "Exif" or "ExifExif"
|
||||||
exifID_ = ID;
|
exifID_ = ID;
|
||||||
id = " *** Exif ***";
|
id = " *** Exif ***";
|
||||||
} else if (name.find("mime\0xmp") != std::string::npos ||
|
} else if (Internal::contains(name, "mime\0xmp") || Internal::contains(name, "mime\0application/rdf+xml")) {
|
||||||
name.find("mime\0application/rdf+xml") != std::string::npos) {
|
|
||||||
xmpID_ = ID;
|
xmpID_ = ID;
|
||||||
id = " *** XMP ***";
|
id = " *** XMP ***";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include "makernote_int.hpp"
|
#include "makernote_int.hpp"
|
||||||
#include "tags_int.hpp"
|
#include "tags_int.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
#include "value.hpp"
|
#include "value.hpp"
|
||||||
|
|
||||||
// + standard includes
|
// + standard includes
|
||||||
@ -2531,8 +2532,8 @@ std::ostream& CanonMakerNote::printFiFileNumber(std::ostream& os, const Value& v
|
|||||||
|
|
||||||
// Ported from Exiftool
|
// Ported from Exiftool
|
||||||
std::string model = pos->toString();
|
std::string model = pos->toString();
|
||||||
if (model.find("20D") != std::string::npos || model.find("350D") != std::string::npos ||
|
if (Internal::contains(model, "20D") || Internal::contains(model, "350D") ||
|
||||||
model.substr(model.size() - 8, 8) == "REBEL XT" || model.find("Kiss Digital N") != std::string::npos) {
|
model.substr(model.size() - 8, 8) == "REBEL XT" || Internal::contains(model, "Kiss Digital N")) {
|
||||||
uint32_t val = value.toUint32();
|
uint32_t val = value.toUint32();
|
||||||
uint32_t dn = (val & 0xffc0) >> 6;
|
uint32_t dn = (val & 0xffc0) >> 6;
|
||||||
uint32_t fn = ((val >> 16) & 0xff) + ((val & 0x3f) << 8);
|
uint32_t fn = ((val >> 16) & 0xff) + ((val & 0x3f) << 8);
|
||||||
@ -2540,9 +2541,8 @@ std::ostream& CanonMakerNote::printFiFileNumber(std::ostream& os, const Value& v
|
|||||||
os.flags(f);
|
os.flags(f);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
if (model.find("30D") != std::string::npos || model.find("400D") != std::string::npos ||
|
if (Internal::contains(model, "30D") || Internal::contains(model, "400D") || Internal::contains(model, "REBEL XTi") ||
|
||||||
model.find("REBEL XTi") != std::string::npos || model.find("Kiss Digital X") != std::string::npos ||
|
Internal::contains(model, "Kiss Digital X") || Internal::contains(model, "K236")) {
|
||||||
model.find("K236") != std::string::npos) {
|
|
||||||
uint32_t val = value.toUint32();
|
uint32_t val = value.toUint32();
|
||||||
uint32_t dn = (val & 0xffc00) >> 10;
|
uint32_t dn = (val & 0xffc00) >> 10;
|
||||||
while (dn < 100)
|
while (dn < 100)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// included header files
|
// included header files
|
||||||
#include "easyaccess.hpp"
|
#include "easyaccess.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
// *****************************************************************************
|
// *****************************************************************************
|
||||||
namespace {
|
namespace {
|
||||||
@ -97,7 +98,7 @@ ExifData::const_iterator isoSpeed(const ExifData& ed) {
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
md->write(os, &ed);
|
md->write(os, &ed);
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (os.str().find("inf") != std::string::npos)
|
if (Internal::contains(os.str(), "inf"))
|
||||||
break;
|
break;
|
||||||
iso_val = parseInt64(os.str(), ok);
|
iso_val = parseInt64(os.str(), ok);
|
||||||
if (ok && iso_val > 0)
|
if (ok && iso_val > 0)
|
||||||
|
|||||||
@ -944,7 +944,7 @@ DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent*
|
|||||||
std::string model = getExifModel(pRoot);
|
std::string model = getExifModel(pRoot);
|
||||||
if (model.empty())
|
if (model.empty())
|
||||||
return buf;
|
return buf;
|
||||||
if (model.find("D50") != std::string::npos) {
|
if (Internal::contains(model, "D50")) {
|
||||||
serial = 0x22;
|
serial = 0x22;
|
||||||
} else {
|
} else {
|
||||||
serial = 0x60;
|
serial = 0x60;
|
||||||
@ -961,7 +961,7 @@ int sonyCsSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, Tif
|
|||||||
if (model.empty())
|
if (model.empty())
|
||||||
return -1;
|
return -1;
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
if (model.find("DSLR-A330") != std::string::npos || model.find("DSLR-A380") != std::string::npos) {
|
if (Internal::contains(model, "DSLR-A330") || Internal::contains(model, "DSLR-A380")) {
|
||||||
idx = 1;
|
idx = 1;
|
||||||
}
|
}
|
||||||
return idx;
|
return idx;
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include "i18n.h" // NLS support.
|
#include "i18n.h" // NLS support.
|
||||||
#include "makernote_int.hpp"
|
#include "makernote_int.hpp"
|
||||||
#include "tags_int.hpp"
|
#include "tags_int.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
#include "value.hpp"
|
#include "value.hpp"
|
||||||
|
|
||||||
// + standard includes
|
// + standard includes
|
||||||
@ -1834,7 +1835,7 @@ std::ostream& Nikon3MakerNote::printAfPointsInFocus(std::ostream& os, const Valu
|
|||||||
auto pos = metadata->findKey(ExifKey("Exif.Image.Model"));
|
auto pos = metadata->findKey(ExifKey("Exif.Image.Model"));
|
||||||
if (pos != metadata->end() && pos->count() != 0) {
|
if (pos != metadata->end() && pos->count() != 0) {
|
||||||
std::string model = pos->toString();
|
std::string model = pos->toString();
|
||||||
if (model.find("NIKON D") != std::string::npos) {
|
if (Internal::contains(model, "NIKON D")) {
|
||||||
dModel = true;
|
dModel = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1867,7 +1868,7 @@ std::ostream& Nikon3MakerNote::print0x0089(std::ostream& os, const Value& value,
|
|||||||
auto pos = metadata->findKey(key);
|
auto pos = metadata->findKey(key);
|
||||||
if (pos != metadata->end() && pos->count() != 0) {
|
if (pos != metadata->end() && pos->count() != 0) {
|
||||||
std::string model = pos->toString();
|
std::string model = pos->toString();
|
||||||
if (model.find("D70") != std::string::npos) {
|
if (Internal::contains(model, "D70")) {
|
||||||
d70 = true;
|
d70 = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "i18n.h" // NLS support.
|
#include "i18n.h" // NLS support.
|
||||||
#include "makernote_int.hpp"
|
#include "makernote_int.hpp"
|
||||||
#include "tags_int.hpp"
|
#include "tags_int.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
#include "value.hpp"
|
#include "value.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
@ -1586,7 +1587,7 @@ std::ostream& OlympusMakerNote::print0x0308(std::ostream& os, const Value& value
|
|||||||
auto pos = metadata->findKey(ExifKey("Exif.Image.Model"));
|
auto pos = metadata->findKey(ExifKey("Exif.Image.Model"));
|
||||||
if (pos != metadata->end() && pos->count() != 0) {
|
if (pos != metadata->end() && pos->count() != 0) {
|
||||||
std::string model = pos->toString();
|
std::string model = pos->toString();
|
||||||
if (model.find("E-3 ") != std::string::npos || model.find("E-30 ") != std::string::npos) {
|
if (Internal::contains(model, "E-3 ") || Internal::contains(model, "E-30 ")) {
|
||||||
E3_E30model = true;
|
E3_E30model = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -646,7 +646,7 @@ static auto getModel(const ExifData* metadata, std::string& val) {
|
|||||||
pos = metadata->findKey(ExifKey("Exif.Sony1.SonyModelID"));
|
pos = metadata->findKey(ExifKey("Exif.Sony1.SonyModelID"));
|
||||||
if (pos != metadata->end() && pos->size() != 0 && pos->typeId() == unsignedShort) {
|
if (pos != metadata->end() && pos->size() != 0 && pos->typeId() == unsignedShort) {
|
||||||
std::string temp = pos->print(metadata);
|
std::string temp = pos->print(metadata);
|
||||||
if (temp.find(' ') == std::string::npos) {
|
if (!Internal::contains(temp, ' ')) {
|
||||||
val = temp;
|
val = temp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -656,7 +656,7 @@ static auto getModel(const ExifData* metadata, std::string& val) {
|
|||||||
pos = metadata->findKey(ExifKey("Exif.Sony2.SonyModelID"));
|
pos = metadata->findKey(ExifKey("Exif.Sony2.SonyModelID"));
|
||||||
if (pos != metadata->end() && pos->size() != 0 && pos->typeId() == unsignedShort) {
|
if (pos != metadata->end() && pos->size() != 0 && pos->typeId() == unsignedShort) {
|
||||||
std::string temp = pos->print(metadata);
|
std::string temp = pos->print(metadata);
|
||||||
if (temp.find(' ') == std::string::npos) {
|
if (!Internal::contains(temp, ' ')) {
|
||||||
val = temp;
|
val = temp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1969,7 +1969,7 @@ std::ostream& SonyMakerNote::printSonyMisc2bLensZoomPosition(std::ostream& os, c
|
|||||||
|
|
||||||
// Models that do not support this tag
|
// Models that do not support this tag
|
||||||
for (auto& m : {"SLT-", "HV", "ILCA-"}) {
|
for (auto& m : {"SLT-", "HV", "ILCA-"}) {
|
||||||
if (model.find(m) != std::string::npos)
|
if (Internal::contains(model, m))
|
||||||
return os << N_("n/a");
|
return os << N_("n/a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1991,7 +1991,7 @@ std::ostream& SonyMakerNote::printSonyMisc2bFocusPosition2(std::ostream& os, con
|
|||||||
|
|
||||||
// Models that do not support this tag
|
// Models that do not support this tag
|
||||||
for (auto& m : {"SLT-", "HV", "ILCA-"}) {
|
for (auto& m : {"SLT-", "HV", "ILCA-"}) {
|
||||||
if (model.find(m) != std::string::npos)
|
if (Internal::contains(model, m))
|
||||||
return os << N_("n/a");
|
return os << N_("n/a");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,15 @@ constexpr bool startsWith(std::string_view s, T start) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr bool contains(std::string_view s, T c) {
|
||||||
|
#ifdef __cpp_lib_string_contains
|
||||||
|
return s.contains(c);
|
||||||
|
#else
|
||||||
|
return s.find(c) != std::string_view::npos;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Returns the uppercase version of \b str
|
/// @brief Returns the uppercase version of \b str
|
||||||
std::string upper(const std::string& str);
|
std::string upper(const std::string& str);
|
||||||
|
|
||||||
|
|||||||
@ -390,8 +390,10 @@ std::string CommentValue::comment(const char* encoding) const {
|
|||||||
}
|
}
|
||||||
bool bAscii = charsetId() == undefined || charsetId() == ascii;
|
bool bAscii = charsetId() == undefined || charsetId() == ascii;
|
||||||
// # 1266 Remove trailing nulls
|
// # 1266 Remove trailing nulls
|
||||||
if (bAscii && c.find('\0') != std::string::npos) {
|
if (bAscii) {
|
||||||
c.resize(c.find('\0'));
|
auto n = c.find('\0');
|
||||||
|
if (n != std::string::npos)
|
||||||
|
c.resize(n);
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -580,8 +580,8 @@ static XMP_Status nsDumper(void* refCon, XMP_StringPtr buffer, XMP_StringLen buf
|
|||||||
// remove blanks: http://stackoverflow.com/questions/83439/remove-spaces-from-stdstring-in-c
|
// remove blanks: http://stackoverflow.com/questions/83439/remove-spaces-from-stdstring-in-c
|
||||||
out.erase(std::remove_if(out.begin(), out.end(), isspace), out.end());
|
out.erase(std::remove_if(out.begin(), out.end(), isspace), out.end());
|
||||||
|
|
||||||
bool bURI = out.find("http://") != std::string::npos;
|
bool bURI = Internal::contains(out, "http://");
|
||||||
bool bNS = out.find(':') != std::string::npos && !bURI;
|
bool bNS = Internal::contains(out, ':') && !bURI;
|
||||||
|
|
||||||
// pop trailing ':' on a namespace
|
// pop trailing ':' on a namespace
|
||||||
if (bNS && !out.empty() && out.back() == ':')
|
if (bNS && !out.empty() && out.back() == ':')
|
||||||
|
|||||||
@ -71,7 +71,7 @@ void XmpSidecar::readMetadata() {
|
|||||||
// #1112 - store dates to deal with loss of TZ information during conversions
|
// #1112 - store dates to deal with loss of TZ information during conversions
|
||||||
for (const auto& xmp : xmpData_) {
|
for (const auto& xmp : xmpData_) {
|
||||||
std::string key(xmp.key());
|
std::string key(xmp.key());
|
||||||
if (key.find("Date") != std::string::npos) {
|
if (Internal::contains(key, "Date")) {
|
||||||
std::string value(xmp.value().toString());
|
std::string value(xmp.value().toString());
|
||||||
dates_[key] = value;
|
dates_[key] = value;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ void XmpSidecar::readMetadata() {
|
|||||||
} // XmpSidecar::readMetadata
|
} // XmpSidecar::readMetadata
|
||||||
|
|
||||||
static bool matchi(const std::string& key, const char* substr) {
|
static bool matchi(const std::string& key, const char* substr) {
|
||||||
return Internal::lower(key).find(substr) != std::string::npos;
|
return Internal::contains(Internal::lower(key), substr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmpSidecar::writeMetadata() {
|
void XmpSidecar::writeMetadata() {
|
||||||
@ -110,7 +110,7 @@ void XmpSidecar::writeMetadata() {
|
|||||||
if (xmpData_.findKey(key) != xmpData_.end()) {
|
if (xmpData_.findKey(key) != xmpData_.end()) {
|
||||||
std::string value_now(xmpData_[sKey].value().toString());
|
std::string value_now(xmpData_[sKey].value().toString());
|
||||||
// std::cout << key << " -> " << value_now << " => " << value_orig << std::endl;
|
// std::cout << key << " -> " << value_now << " => " << value_orig << std::endl;
|
||||||
if (value_orig.find(value_now.substr(0, 10)) != std::string::npos) {
|
if (Internal::contains(value_orig, value_now.substr(0, 10))) {
|
||||||
xmpData_[sKey] = value_orig;
|
xmpData_[sKey] = value_orig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
#include <exiv2/exiv2.hpp>
|
#include <exiv2/exiv2.hpp>
|
||||||
// File under test
|
// File under test
|
||||||
#include <exiv2/futils.hpp>
|
#include <exiv2/futils.hpp>
|
||||||
@ -32,7 +34,7 @@ TEST(strError, returnSuccessAfterClosingFile) {
|
|||||||
std::ofstream auxFile(tmpFile.c_str());
|
std::ofstream auxFile(tmpFile.c_str());
|
||||||
auxFile.close();
|
auxFile.close();
|
||||||
fs::remove(tmpFile.c_str());
|
fs::remove(tmpFile.c_str());
|
||||||
ASSERT_TRUE(strError().find("(errno = 0)") != std::string::npos);
|
ASSERT_TRUE(Internal::contains(strError(), "(errno = 0)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) {
|
TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) {
|
||||||
@ -42,7 +44,7 @@ TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) {
|
|||||||
|
|
||||||
TEST(strError, doNotRecognizeUnknownError) {
|
TEST(strError, doNotRecognizeUnknownError) {
|
||||||
errno = 9999;
|
errno = 9999;
|
||||||
ASSERT_TRUE(strError().find("(errno = 9999)") != std::string::npos);
|
ASSERT_TRUE(Internal::contains(strError(), "(errno = 9999)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(getEnv, getsDefaultValueWhenExpectedEnvVariableDoesNotExist) {
|
TEST(getEnv, getsDefaultValueWhenExpectedEnvVariableDoesNotExist) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user