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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user