mirror of https://github.com/stella-emu/stella.git
some fixes and cleanup
This commit is contained in:
parent
b51d6c2fce
commit
50db2abc50
|
@ -320,6 +320,10 @@ namespace BSPF
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Search if string contains pattern including '?' as joker.
|
||||
// @param str The searched string
|
||||
// @param pattern The pattern to search for
|
||||
// @return Position of pattern in string.
|
||||
inline size_t matchWithJoker(const string& str, const string& pattern)
|
||||
{
|
||||
if(str.length() >= pattern.length())
|
||||
|
@ -346,6 +350,11 @@ namespace BSPF
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Search if string contains pattern including wildcard '*'
|
||||
// and '?' as joker.
|
||||
// @param str The searched string
|
||||
// @param pattern The pattern to search for
|
||||
// @return True if pattern was found.
|
||||
inline bool matchWithWildcards(const string& str, const string& pattern)
|
||||
{
|
||||
string pat = pattern;
|
||||
|
|
|
@ -302,8 +302,8 @@ class FSNode
|
|||
* and replace the extension (if present) with the given one. If no
|
||||
* extension is present, the given one is appended instead.
|
||||
*/
|
||||
string getNameWithExt(const string& ext) const;
|
||||
string getPathWithExt(const string& ext) const;
|
||||
string getNameWithExt(const string& ext = "") const;
|
||||
string getPathWithExt(const string& ext = "") const;
|
||||
|
||||
private:
|
||||
explicit FSNode(const AbstractFSNodePtr& realNode);
|
||||
|
|
|
@ -561,65 +561,6 @@ string LauncherDialog::getRomDir()
|
|||
return tmpromdir != EmptyString ? tmpromdir : settings.getString("romdir");
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
size_t LauncherDialog::matchWithJoker(const string& str, const string& pattern)
|
||||
{
|
||||
if(str.length() >= pattern.length())
|
||||
{
|
||||
// optimize a bit
|
||||
if(pattern.find('?') != string::npos)
|
||||
{
|
||||
for(size_t pos = 0; pos < str.length() - pattern.length() + 1; ++pos)
|
||||
{
|
||||
bool found = true;
|
||||
|
||||
for(size_t i = 0; found && i < pattern.length(); ++i)
|
||||
if(pattern[i] != str[pos + i] && pattern[i] != '?')
|
||||
found = false;
|
||||
|
||||
if(found)
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
else
|
||||
return str.find(pattern);
|
||||
}
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool LauncherDialog::matchWithWildcards(const string& str, const string& pattern)
|
||||
{
|
||||
string pat = pattern;
|
||||
|
||||
// remove leading and trailing '*'
|
||||
size_t i = 0;
|
||||
while(pat[i++] == '*');
|
||||
pat = pat.substr(i - 1);
|
||||
|
||||
i = pat.length();
|
||||
while(pat[--i] == '*');
|
||||
pat.erase(i + 1);
|
||||
|
||||
// Search for first '*'
|
||||
const size_t pos = pat.find('*');
|
||||
|
||||
if(pos != string::npos)
|
||||
{
|
||||
// '*' found, split pattern into left and right part, search recursively
|
||||
const string leftPat = pat.substr(0, pos);
|
||||
const string rightPat = pat.substr(pos + 1);
|
||||
const size_t posLeft = matchWithJoker(str, leftPat);
|
||||
|
||||
if(posLeft != string::npos)
|
||||
return matchWithWildcards(str.substr(pos + posLeft), rightPat);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
// no further '*' found
|
||||
return matchWithJoker(str, pat) != string::npos;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool LauncherDialog::matchWithWildcardsIgnoreCase(const string& str, const string& pattern)
|
||||
{
|
||||
|
@ -629,7 +570,7 @@ bool LauncherDialog::matchWithWildcardsIgnoreCase(const string& str, const strin
|
|||
BSPF::toUpperCase(in);
|
||||
BSPF::toUpperCase(pat);
|
||||
|
||||
return matchWithWildcards(in, pat);
|
||||
return BSPF::matchWithWildcards(in, pat);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -141,27 +141,6 @@ class LauncherDialog : public Dialog, CommandSender
|
|||
*/
|
||||
bool matchWithWildcardsIgnoreCase(const string& str, const string& pattern);
|
||||
|
||||
/**
|
||||
Search if string contains pattern including wildcard '*'
|
||||
and '?' as joker.
|
||||
|
||||
@param str The searched string
|
||||
@param pattern The pattern to search for
|
||||
|
||||
@return True if pattern was found.
|
||||
*/
|
||||
bool matchWithWildcards(const string& str, const string& pattern);
|
||||
|
||||
/**
|
||||
Search if string contains pattern including '?' as joker.
|
||||
|
||||
@param str The searched string
|
||||
@param pattern The pattern to search for
|
||||
|
||||
@return Position of pattern in string.
|
||||
*/
|
||||
size_t matchWithJoker(const string& str, const string& pattern);
|
||||
|
||||
void applyFiltering();
|
||||
|
||||
float getRomInfoZoom(int listHeight) const;
|
||||
|
|
|
@ -169,8 +169,15 @@ bool RomImageWidget::getImageList(const string& filename)
|
|||
});
|
||||
|
||||
FSNode node(instance().snapshotLoadDir().getPath());
|
||||
|
||||
node.getChildren(myImageList, FSNode::ListMode::FilesOnly, filter, false, false);
|
||||
|
||||
// Sort again, not considering extensions, else <filename.png> would be at the end of the list
|
||||
std::sort(myImageList.begin(), myImageList.end(),
|
||||
[](const FSNode& node1, const FSNode& node2)
|
||||
{
|
||||
return BSPF::compareIgnoreCase(node1.getNameWithExt(), node2.getNameWithExt()) < 0;
|
||||
}
|
||||
);
|
||||
return myImageList.size() > 0;
|
||||
}
|
||||
|
||||
|
@ -271,7 +278,7 @@ void RomImageWidget::drawWidget(bool hilite)
|
|||
|
||||
myNavSurface->invalidate();
|
||||
if(isHighlighted() &&
|
||||
((leftArrow && myImageIdx) || (!leftArrow && myImageIdx < myImageList.size() - 1)) || true)
|
||||
((leftArrow && myImageIdx) || (!leftArrow && myImageIdx < myImageList.size() - 1)))
|
||||
{
|
||||
const int w = _w / 64;
|
||||
const int w2 = 1; // w / 2;
|
||||
|
|
Loading…
Reference in New Issue