diff --git a/src/poly/fs.cc b/src/poly/fs.cc index 8ae83a373..fed8e177b 100644 --- a/src/poly/fs.cc +++ b/src/poly/fs.cc @@ -109,49 +109,49 @@ WildcardFlags WildcardFlags::LAST(false, true); WildcardFlags::WildcardFlags() : FromStart(false) , ToEnd(false) - , WithCase(false) { } WildcardFlags::WildcardFlags(bool start, bool end) : FromStart(start) , ToEnd(end) - , WithCase(false) { } -WildcardRule::WildcardRule(std::string str_match, const WildcardFlags &flags) +WildcardRule::WildcardRule(const std::string& str_match, const WildcardFlags& flags) : match(str_match) , rules(flags) -{ } - -bool WildcardRule::Check(std::string& str) const { - if( match.empty() ) { + std::transform(match.begin(), match.end(), match.begin(), tolower); +} + +bool WildcardRule::Check(const std::string& str_lower, std::string::size_type& offset) const +{ + if (match.empty()) { return true; } - if( str.size() < match.size() ) { + if ((str_lower.size() - offset) < match.size()) { return false; } - std::string::size_type result(str.find(match)); + std::string::size_type result(str_lower.find(match, offset)); - if( result != std::string::npos ) { - if( rules.FromStart && result != 0 ) { + if (result != std::string::npos) { + if (rules.FromStart && result != offset) { return false; } - if( rules.ToEnd && result != ( ( str.size() -1 ) - match.size() ) ) { + if (rules.ToEnd && result != (str_lower.size() - match.size())) { return false; } - str.erase(0, result + match.size()); + offset = (result + match.size()); return true; } return false; } -void WildcardEngine::PreparePattern(const std::string &pattern) +void WildcardEngine::PreparePattern(const std::string& pattern) { rules.clear(); @@ -172,17 +172,19 @@ void WildcardEngine::PreparePattern(const std::string &pattern) } } -void WildcardEngine::SetRule(const std::string &pattern) +void WildcardEngine::SetRule(const std::string& pattern) { PreparePattern(pattern); } -bool WildcardEngine::Match(const std::string &str) const +bool WildcardEngine::Match(const std::string& str) const { - std::string str_copy(str); + std::string str_lc; + std::transform(str.begin(), str.end(), std::back_inserter(str_lc), tolower); + std::string::size_type offset(0); for (const auto& rule : rules) { - if (!(rule.Check(str_copy))) { + if (!(rule.Check(str_lc, offset))) { return false; } } diff --git a/src/poly/fs.h b/src/poly/fs.h index e6c73c50b..9d23637e9 100644 --- a/src/poly/fs.h +++ b/src/poly/fs.h @@ -45,8 +45,7 @@ class WildcardFlags public: bool FromStart: 1, - ToEnd : 1, - WithCase : 1; // Unused for now + ToEnd : 1; WildcardFlags(); WildcardFlags(bool start, bool end); @@ -58,8 +57,8 @@ public: class WildcardRule { public: - WildcardRule(std::string str_match, const WildcardFlags &flags); - bool Check(std::string& str) const; + WildcardRule(const std::string& str_match, const WildcardFlags &flags); + bool Check(const std::string& str_lower, std::string::size_type& offset) const; private: std::string match; @@ -70,6 +69,8 @@ class WildcardEngine { public: void SetRule(const std::string &pattern); + + // Always ignoring case bool Match(const std::string &str) const; private: std::vector rules; diff --git a/src/xenia/kernel/fs/gdfx.cc b/src/xenia/kernel/fs/gdfx.cc index 38fa73195..b9632df27 100644 --- a/src/xenia/kernel/fs/gdfx.cc +++ b/src/xenia/kernel/fs/gdfx.cc @@ -166,7 +166,6 @@ bool GDFX::ReadEntry(ParseState& state, const uint8_t* buffer, GDFXEntry* entry = new GDFXEntry(); entry->name = std::string(name, name_length); - entry->name.append(1, '\0'); entry->attributes = (X_FILE_ATTRIBUTES)attributes; // Add to parent. diff --git a/src/xenia/kernel/fs/stfs.cc b/src/xenia/kernel/fs/stfs.cc index f7593b2eb..b749c4d76 100644 --- a/src/xenia/kernel/fs/stfs.cc +++ b/src/xenia/kernel/fs/stfs.cc @@ -213,7 +213,6 @@ STFS::Error STFS::ReadAllEntries(const uint8_t* map_ptr) { auto entry = std::make_unique(); entry->name = std::string((char*)filename, filename_length_flags & 0x3F); - entry->name.append(1, '\0'); // bit 0x40 = consecutive blocks (not fragmented?) if (filename_length_flags & 0x80) { entry->attributes = X_FILE_ATTRIBUTE_DIRECTORY;