Remove startsWith from utils

main
Luis Díaz Más 3 years ago committed by Luis Diaz
parent d1524e3d96
commit 49fbfb44a3

@ -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)
{

@ -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

@ -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;
}

@ -118,11 +118,4 @@ namespace Util {
index++;
}
}
bool startsWith(const std::string& s, const std::string& start)
{
return s.find(start) == 0;
}
} // namespace Util

@ -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<CharT,Traits,Allocator>::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<CharT,Traits,Allocator>::starts_with().
*/
bool startsWith(const std::string& s, const std::string& start);
} // namespace Util
#endif // #ifndef UTILS_HPP_

@ -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"));
}

Loading…
Cancel
Save