|
@@ -230,27 +230,30 @@ void BaseImporter::GetExtensionList(std::set<std::string> &extensions) {
|
|
const char *ext0,
|
|
const char *ext0,
|
|
const char *ext1,
|
|
const char *ext1,
|
|
const char *ext2) {
|
|
const char *ext2) {
|
|
- std::string::size_type pos = pFile.find_last_of('.');
|
|
|
|
-
|
|
|
|
- // no file extension - can't read
|
|
|
|
- if (pos == std::string::npos) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const char *ext_real = &pFile[pos + 1];
|
|
|
|
- if (!ASSIMP_stricmp(ext_real, ext0)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // check for other, optional, file extensions
|
|
|
|
- if (ext1 && !ASSIMP_stricmp(ext_real, ext1)) {
|
|
|
|
- return true;
|
|
|
|
|
|
+ std::set<std::string> extensions;
|
|
|
|
+ for (const char* ext : {ext0, ext1, ext2}) {
|
|
|
|
+ if (ext == nullptr) continue;
|
|
|
|
+ extensions.emplace(ext);
|
|
}
|
|
}
|
|
|
|
+ return HasExtension(pFile, extensions);
|
|
|
|
+}
|
|
|
|
|
|
- if (ext2 && !ASSIMP_stricmp(ext_real, ext2)) {
|
|
|
|
- return true;
|
|
|
|
|
|
+// ------------------------------------------------------------------------------------------------
|
|
|
|
+// Check for file extension
|
|
|
|
+/*static*/ bool BaseImporter::HasExtension(const std::string &pFile, const std::set<std::string> &extensions) {
|
|
|
|
+ // CAUTION: Do not just search for the extension!
|
|
|
|
+ // GetExtension() returns the part after the *last* dot, but some extensions
|
|
|
|
+ // have dots inside them, e.g. ogre.mesh.xml. Compare the entire end of the
|
|
|
|
+ // string.
|
|
|
|
+ for (const std::string& ext : extensions) {
|
|
|
|
+ // Yay for C++<20 not having std::string::ends_with()
|
|
|
|
+ const std::string dotExt = "." + ext;
|
|
|
|
+ if (dotExt.length() > pFile.length()) continue;
|
|
|
|
+ // Possible optimization: Fetch the lowercase filename!
|
|
|
|
+ if (0 == ASSIMP_stricmp(pFile.c_str() + pFile.length() - dotExt.length(), dotExt.c_str())) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|