Skip to content

Commit

Permalink
(Sim)RM95: Use detection suggested by @florianessl
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Jan 20, 2025
1 parent 9dc544e commit 64f68e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
40 changes: 31 additions & 9 deletions src/directory_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,40 @@ std::unique_ptr<DirectoryTree> DirectoryTree::Create(Filesystem& fs) {
}

bool DirectoryTree::WildcardMatch(const StringView& pattern, const StringView& text) {
if (pattern.length() != text.length()) {
return false;
// Limitations: * and ? cannot be mixed, * only at beginning and end of string
// Input is already lower-cased
if (pattern.empty() && text.empty()) {
return true;
}

std::string pattern_norm = make_key(pattern);
std::string text_norm = make_key(text);
bool begin_wildcard = pattern.starts_with('*');
bool end_wildcard = pattern.ends_with('*');

return std::equal(pattern_norm.begin(), pattern_norm.end(),
text_norm.begin(),
[](char p, char t) {
return p == '?' || p == t;
});
if (begin_wildcard || end_wildcard && text.size() > 0) {

Check warning on line 64 in src/directory_tree.cpp

View workflow job for this annotation

GitHub Actions / ubuntu:22.04

suggest parentheses around '&&' within '||' [-Wparentheses]

Check warning on line 64 in src/directory_tree.cpp

View workflow job for this annotation

GitHub Actions / debian:12

suggest parentheses around '&&' within '||' [-Wparentheses]
// * handling
bool found = false;
if (begin_wildcard) {
found |= text.ends_with(pattern.substr(1));
}
if (end_wildcard) {
found |= text.starts_with(pattern.substr(0, pattern.size() - 1));
}
return found;
} else {
// ? handling
if (pattern.length() != text.length()) {
return false;
}

std::string pattern_norm = make_key(pattern);
std::string text_norm = make_key(text);

return std::equal(pattern_norm.begin(), pattern_norm.end(),
text_norm.begin(),
[](char p, char t) {
return p == '?' || p == t;
});
}
}

DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory(StringView path) const {
Expand Down
12 changes: 6 additions & 6 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ FileFinder::ProjectType FileFinder::GetProjectType(const FilesystemView &fs) {
return FileFinder::ProjectType::Encrypted2k3Maniacs;
}

if (!fs.FindFile("Game.RPG").empty()) {
return FileFinder::ProjectType::RpgMaker95;
}

if (!fs.FindFile("Game.DAT").empty()) {
return FileFinder::ProjectType::SimRpgMaker95;
if (!fs.FindFile("SWNAME.DAT").empty()) {
if (!fs.FindFile("GEOLOGY.DAT").empty()) {
return FileFinder::ProjectType::SimRpgMaker95;
} else if (args.path = "*.RPG"; !fs.FindFile(args).empty()) {
return FileFinder::ProjectType::RpgMaker95;
}
}

return FileFinder::ProjectType::Unknown;
Expand Down

0 comments on commit 64f68e4

Please sign in to comment.