Merge pull request #355 from tdaede/lowercase

Make filename endings case insensitive.
This commit is contained in:
David Given
2021-12-01 17:23:08 +01:00
committed by GitHub
2 changed files with 5 additions and 3 deletions

View File

@@ -58,12 +58,10 @@ void ImageReader::updateConfigForFilename(ImageReaderProto* proto, const std::st
{".dim", [&]() { proto->mutable_dim(); }},
{".diskcopy", [&]() { proto->mutable_diskcopy(); }},
{".fdi", [&]() { proto->mutable_fdi(); }},
{".FDI", [&]() { proto->mutable_fdi(); }},
{".img", [&]() { proto->mutable_img(); }},
{".st", [&]() { proto->mutable_img(); }},
{".nsi", [&]() { proto->mutable_nsi(); }},
{".td0", [&]() { proto->mutable_td0(); }},
{".TD0", [&]() { proto->mutable_td0(); }},
{".xdf", [&]() { proto->mutable_img(); }},
};

View File

@@ -7,11 +7,15 @@ bool beginsWith(const std::string& value, const std::string& ending)
return std::equal(ending.begin(), ending.end(), value.begin());
}
// Case-insensitive for endings within ASCII.
bool endsWith(const std::string& value, const std::string& ending)
{
if (ending.size() > value.size())
return false;
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
std::string lowercase(ending.size(), 0);
std::transform(value.rbegin(), value.rbegin() + ending.size(), lowercase.begin(), [](unsigned char c){ return std::tolower(c); });
return std::equal(ending.rbegin(), ending.rend(), value.rbegin()) ||
std::equal(ending.rbegin(), ending.rend(), lowercase.begin());
}