Make extension checks case-insensitive (#273)

## Summary

* Implement new `StringUtils::checkFileExtension` which does case
insensitive checking
* Move all checks over to this
This commit is contained in:
Dave Allie
2026-01-07 20:07:23 +10:00
committed by GitHub
parent 0cc2c64df2
commit 46fa186b82
7 changed files with 38 additions and 34 deletions

View File

@@ -1,5 +1,7 @@
#include "StringUtils.h"
#include <cstring>
namespace StringUtils {
std::string sanitizeFilename(const std::string& name, size_t maxLength) {
@@ -33,4 +35,18 @@ std::string sanitizeFilename(const std::string& name, size_t maxLength) {
return result.empty() ? "book" : result;
}
bool checkFileExtension(const std::string& fileName, const char* extension) {
if (fileName.length() < strlen(extension)) {
return false;
}
const std::string fileExt = fileName.substr(fileName.length() - strlen(extension));
for (size_t i = 0; i < fileExt.length(); i++) {
if (tolower(fileExt[i]) != tolower(extension[i])) {
return false;
}
}
return true;
}
} // namespace StringUtils