Replace raw loop for any_of

This commit is contained in:
Luis Díaz Más 2022-02-17 22:35:42 +01:00
parent 59f4d0de27
commit 476a5e23f9
5 changed files with 25 additions and 10 deletions

View File

@ -36,6 +36,7 @@ add_library( exiv2lib_int OBJECT
tifffwd_int.hpp
timegm.h
unused.h
utils.hpp utils.cpp
)
set(PUBLIC_HEADERS

View File

@ -32,6 +32,7 @@
#include "basicio.hpp"
#include "error.hpp"
#include "futils.hpp"
#include "utils.hpp"
#include "version.hpp"
// + standard includes
@ -103,11 +104,6 @@ namespace {
// closing part of all valid XMP trailers
const std::string xmpTrailerEnd = "?>";
constexpr bool startsWith(const std::string_view& s, const std::string_view& start)
{
return s.find(start) == 0;
}
//! Write data into temp file, taking care of errors
void writeTemp(BasicIo& tempIo, const byte* data, size_t size)
{

View File

@ -32,6 +32,7 @@
#include "tiffvisitor_int.hpp"
#include "tiffimage.hpp"
#include "tiffimage_int.hpp"
#include "utils.hpp"
// + standard includes
#include <string>
@ -1223,11 +1224,8 @@ namespace Exiv2 {
{
// Not valid for models beginning
std::string model = getExifModel(pRoot);
for (auto& m : { "SLT-", "HV", "ILCA-" }) {
if (model.find(m) == 0)
return -1;
}
return 0;
const std::vector<std::string> strs { "SLT-", "HV", "ILCA-"};
return std::any_of(strs.begin(), strs.end(), [&model](auto& m){return startsWith(model, m);}) ? -1 : 0;
}
int sonyMisc2bSelector(uint16_t /*tag*/, const byte* /*pData*/, uint32_t /*size*/, TiffComponent* const pRoot)

9
src/utils.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "utils.hpp"
namespace Exiv2
{
bool startsWith(const std::string_view& s, const std::string_view& start)
{
return s.find(start) == 0;
}
}

11
src/utils.hpp Normal file
View File

@ -0,0 +1,11 @@
#ifndef EXIV2_UTILS_HPP
#define EXIV2_UTILS_HPP
#include <string_view>
namespace Exiv2
{
bool startsWith(const std::string_view& s, const std::string_view& start);
}
#endif // EXIV2_UTILS_HPP