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()
|
WildcardFlags::WildcardFlags()
|
||||||
: FromStart(false)
|
: FromStart(false)
|
||||||
, ToEnd(false)
|
, ToEnd(false)
|
||||||
, WithCase(false)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
WildcardFlags::WildcardFlags(bool start, bool end)
|
WildcardFlags::WildcardFlags(bool start, bool end)
|
||||||
: FromStart(start)
|
: FromStart(start)
|
||||||
, ToEnd(end)
|
, 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)
|
: match(str_match)
|
||||||
, rules(flags)
|
, 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( str.size() < match.size() ) {
|
if ((str_lower.size() - offset) < match.size()) {
|
||||||
return false;
|
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 (result != std::string::npos) {
|
||||||
if( rules.FromStart && result != 0 ) {
|
if (rules.FromStart && result != offset) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( rules.ToEnd && result != ( ( str.size() -1 ) - match.size() ) ) {
|
if (rules.ToEnd && result != (str_lower.size() - match.size())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str.erase(0, result + match.size());
|
offset = (result + match.size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WildcardEngine::PreparePattern(const std::string &pattern)
|
void WildcardEngine::PreparePattern(const std::string& pattern)
|
||||||
{
|
{
|
||||||
rules.clear();
|
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);
|
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) {
|
for (const auto& rule : rules) {
|
||||||
if (!(rule.Check(str_copy))) {
|
if (!(rule.Check(str_lc, offset))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,7 @@ class WildcardFlags
|
||||||
public:
|
public:
|
||||||
bool
|
bool
|
||||||
FromStart: 1,
|
FromStart: 1,
|
||||||
ToEnd : 1,
|
ToEnd : 1;
|
||||||
WithCase : 1; // Unused for now
|
|
||||||
|
|
||||||
WildcardFlags();
|
WildcardFlags();
|
||||||
WildcardFlags(bool start, bool end);
|
WildcardFlags(bool start, bool end);
|
||||||
|
@ -58,8 +57,8 @@ public:
|
||||||
class WildcardRule
|
class WildcardRule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WildcardRule(std::string str_match, const WildcardFlags &flags);
|
WildcardRule(const std::string& str_match, const WildcardFlags &flags);
|
||||||
bool Check(std::string& str) const;
|
bool Check(const std::string& str_lower, std::string::size_type& offset) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string match;
|
std::string match;
|
||||||
|
@ -70,6 +69,8 @@ class WildcardEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void SetRule(const std::string &pattern);
|
void SetRule(const std::string &pattern);
|
||||||
|
|
||||||
|
// Always ignoring case
|
||||||
bool Match(const std::string &str) const;
|
bool Match(const std::string &str) const;
|
||||||
private:
|
private:
|
||||||
std::vector<WildcardRule> rules;
|
std::vector<WildcardRule> rules;
|
||||||
|
|
|
@ -166,7 +166,6 @@ bool GDFX::ReadEntry(ParseState& state, const uint8_t* buffer,
|
||||||
|
|
||||||
GDFXEntry* entry = new GDFXEntry();
|
GDFXEntry* entry = new GDFXEntry();
|
||||||
entry->name = std::string(name, name_length);
|
entry->name = std::string(name, name_length);
|
||||||
entry->name.append(1, '\0');
|
|
||||||
entry->attributes = (X_FILE_ATTRIBUTES)attributes;
|
entry->attributes = (X_FILE_ATTRIBUTES)attributes;
|
||||||
|
|
||||||
// Add to parent.
|
// Add to parent.
|
||||||
|
|
|
@ -213,7 +213,6 @@ STFS::Error STFS::ReadAllEntries(const uint8_t* map_ptr) {
|
||||||
|
|
||||||
auto entry = std::make_unique<STFSEntry>();
|
auto entry = std::make_unique<STFSEntry>();
|
||||||
entry->name = std::string((char*)filename, filename_length_flags & 0x3F);
|
entry->name = std::string((char*)filename, filename_length_flags & 0x3F);
|
||||||
entry->name.append(1, '\0');
|
|
||||||
// bit 0x40 = consecutive blocks (not fragmented?)
|
// bit 0x40 = consecutive blocks (not fragmented?)
|
||||||
if (filename_length_flags & 0x80) {
|
if (filename_length_flags & 0x80) {
|
||||||
entry->attributes = X_FILE_ATTRIBUTE_DIRECTORY;
|
entry->attributes = X_FILE_ATTRIBUTE_DIRECTORY;
|
||||||
|
|
Loading…
Reference in New Issue