mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 18:53:09 +02:00
Simplified file extension filtering code
Don't create any temporary strings, just use the d_name field and strcasecmp.
This commit is contained in:
parent
404b2a1029
commit
47d349f78b
@ -124,33 +124,18 @@ void FileLister::browse(const string& path, bool clean)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
string file = dptr->d_name;
|
// Determine file extension.
|
||||||
for (vector<string>::iterator it = filter.begin(); it != filter.end(); ++it) {
|
const char *ext = strrchr(dptr->d_name, '.');
|
||||||
if (file.find('.') == string::npos) {
|
if (ext) ext++; else ext = "";
|
||||||
if (!it->empty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
fileSet.insert(file);
|
for (auto& filterExt : filter) {
|
||||||
|
// Note: strcasecmp can't compare multi-byte UTF-8 characters,
|
||||||
|
// but the filtered file extensions don't contain any of
|
||||||
|
// those.
|
||||||
|
if (strcasecmp(ext, filterExt.c_str()) == 0) {
|
||||||
|
fileSet.insert(string(dptr->d_name));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it->length() < file.length()) {
|
|
||||||
if (file[file.length() - it->length() - 1] != '.')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string file_lowercase =
|
|
||||||
file.substr(file.length() - it->length());
|
|
||||||
|
|
||||||
/* XXX: This won't accept UTF-8 codes.
|
|
||||||
* Thanksfully file extensions shouldn't contain any. */
|
|
||||||
transform(file_lowercase.begin(), file_lowercase.end(),
|
|
||||||
file_lowercase.begin(), ::tolower);
|
|
||||||
|
|
||||||
if (file_lowercase.compare(0, it->length(), *it) == 0) {
|
|
||||||
fileSet.insert(file);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user