Adjustments to wildcard engine
Fixed incorrect logic when checking at the end of the string - some of the names had an added null character Removed case sensitivity
This commit is contained in:
parent
17bc561045
commit
d091f12c81
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<WildcardRule> rules;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -213,7 +213,6 @@ STFS::Error STFS::ReadAllEntries(const uint8_t* map_ptr) {
|
|||
|
||||
auto entry = std::make_unique<STFSEntry>();
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue