From 476a5e23f9d9126942d2cfd8436ce08787d1c275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Thu, 17 Feb 2022 22:35:42 +0100 Subject: [PATCH] Replace raw loop for any_of --- src/CMakeLists.txt | 1 + src/epsimage.cpp | 6 +----- src/makernote_int.cpp | 8 +++----- src/utils.cpp | 9 +++++++++ src/utils.hpp | 11 +++++++++++ 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 src/utils.cpp create mode 100644 src/utils.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a4990b4e..1e4917cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ add_library( exiv2lib_int OBJECT tifffwd_int.hpp timegm.h unused.h + utils.hpp utils.cpp ) set(PUBLIC_HEADERS diff --git a/src/epsimage.cpp b/src/epsimage.cpp index 52556eae..d87ed7f9 100644 --- a/src/epsimage.cpp +++ b/src/epsimage.cpp @@ -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) { diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 5863eb01..e0ed6255 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -32,6 +32,7 @@ #include "tiffvisitor_int.hpp" #include "tiffimage.hpp" #include "tiffimage_int.hpp" +#include "utils.hpp" // + standard includes #include @@ -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 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) diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 00000000..479d79de --- /dev/null +++ b/src/utils.cpp @@ -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; + } +} diff --git a/src/utils.hpp b/src/utils.hpp new file mode 100644 index 00000000..9b790116 --- /dev/null +++ b/src/utils.hpp @@ -0,0 +1,11 @@ +#ifndef EXIV2_UTILS_HPP +#define EXIV2_UTILS_HPP + +#include + +namespace Exiv2 +{ + bool startsWith(const std::string_view& s, const std::string_view& start); +} + +#endif // EXIV2_UTILS_HPP