diff --git a/src/epsimage.cpp b/src/epsimage.cpp index 1358faea..9fcaeea6 100644 --- a/src/epsimage.cpp +++ b/src/epsimage.cpp @@ -105,6 +105,11 @@ namespace { // closing part of all valid XMP trailers const std::string xmpTrailerEnd = "?>"; + bool startsWith(const std::string& s, const std::string& 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 164b5bb8..cf8a0444 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -1219,16 +1219,18 @@ namespace Exiv2 { }; return std::find(std::begin(models), std::end(models), getExifModel(pRoot)) != std::end(models) ? 0 : -1; } + int sony2FpSelector(uint16_t /*tag*/, const byte* /*pData*/, uint32_t /*size*/, TiffComponent* const pRoot) { // Not valid for models beginning std::string model = getExifModel(pRoot); for (auto& m : { "SLT-", "HV", "ILCA-" }) { - if (Util::startsWith(model, m)) + if (model.find(m) == 0) return -1; } return 0; } + int sonyMisc2bSelector(uint16_t /*tag*/, const byte* /*pData*/, uint32_t /*size*/, TiffComponent* const pRoot) { // From Exiftool: https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool/Sony.pm diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index 0cc2f0bc..b168170d 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -905,7 +905,7 @@ namespace Exiv2 { // Ranges of models that do not support this tag std::string model = pos->toString(); for (auto& m : { "DSC-", "Stellar" }) { - if (Util::startsWith(model, m)) { + if (model.find(m) == 0) { os << N_("n/a"); return os; } diff --git a/src/utils.cpp b/src/utils.cpp index 097954c8..20f05bbd 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -118,11 +118,4 @@ namespace Util { index++; } } - - bool startsWith(const std::string& s, const std::string& start) - { - return s.find(start) == 0; - } - - } // namespace Util diff --git a/src/utils.hpp b/src/utils.hpp index 22beeb57..3a23099a 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -77,15 +77,6 @@ namespace Util { */ void replace(std::string& text, const std::string& searchText, const std::string& replaceText); - // TODO: When using C++20, replace with std::basic_string::starts_with() - // (suggested in https://github.com/Exiv2/exiv2/pull/1777). - /*! - @brief Tests if \em start occurs at the beginning of \em s. - Returns true if found, else false. - When Exiv2 uses C++20, this will be replaced with - std::basic_string::starts_with(). - */ - bool startsWith(const std::string& s, const std::string& start); } // namespace Util #endif // #ifndef UTILS_HPP_ diff --git a/unitTests/test_utils.cpp b/unitTests/test_utils.cpp index 530d5b1a..711176f5 100644 --- a/unitTests/test_utils.cpp +++ b/unitTests/test_utils.cpp @@ -70,22 +70,3 @@ TEST(suffix, returnsEmptyStringWithFilesWithoutExtension) ASSERT_EQ("", Util::suffix("/home/luis/file")); ASSERT_EQ("", Util::suffix("c:\\luis\\file")); } - -TEST(startsWith, returnsTrueWhenReferenceStringStartsWithSpecifiedString) -{ - ASSERT_TRUE(Util::startsWith("aabbccdd", "aab")); - ASSERT_TRUE(Util::startsWith("aabbccdd", "aa")); - ASSERT_TRUE(Util::startsWith("aabbccdd", "a")); -} - -TEST(startsWith, returnsFalseWhenReferenceStringDoesNotStartWithSpecifiedString) -{ - ASSERT_FALSE(Util::startsWith("aabbccdd", "b")); - ASSERT_FALSE(Util::startsWith("aabbccdd", "ab")); - ASSERT_FALSE(Util::startsWith("aabbccdd", "aac")); -} - -TEST(startsWith, returnsFalseWhenTargetStringIsLongerThanReference) -{ - ASSERT_FALSE(Util::startsWith("aabb", "aabbC")); -}