mirror of https://github.com/stella-emu/stella.git
Use regular expressions to match console type in ROM filename.
This commit is contained in:
parent
11f4846f21
commit
c95acefffd
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include "AtariVox.hxx"
|
#include "AtariVox.hxx"
|
||||||
#include "Booster.hxx"
|
#include "Booster.hxx"
|
||||||
|
@ -275,44 +276,35 @@ void Console::redetectFrameLayout()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string Console::formatFromFilename() const
|
string Console::formatFromFilename() const
|
||||||
{
|
{
|
||||||
std::map<string, string> Pattern = {
|
static const BSPF::array2D<string, 6, 2> Pattern = {{
|
||||||
{"NTSC50", "NTSC50"}, {"NTSC 50", "NTSC50"}, {"NTSC-50", "NTSC50"},
|
{ R"([ _\-(\[<]+NTSC[ -]?50)", "NTSC50" },
|
||||||
{"PAL60", "PAL60"}, {"PAL 60", "PAL60"}, {"PAL-60", "PAL60"},
|
{ R"([ _\-(\[<]+PAL[ -]?60)", "PAL60" },
|
||||||
{"SECAM60", "SECAM60"}, {"SECAM 60", "SECAM60"}, {"SECAM-60", "SECAM60"},
|
{ R"([ _\-(\[<]+SECAM[ -]?60)", "SECAM60" },
|
||||||
{"NTSC60", "NTSC" }, {"NTSC", "NTSC"}, // also finds "NTSC 60" and "NTSC-60"
|
{ R"([ _\-(\[<]+NTSC[ _\-)\]>]?)", "NTSC" },
|
||||||
{"PAL50", "PAL" }, {"PAL", "PAL"}, // also finds "PAL 50" and "PAL-50"
|
{ R"([ _\-(\[<]+PAL[ _\-)\]>]?)", "PAL" },
|
||||||
{"SECAM50", "SECAM"}, {"SECAM", "SECAM"}, // also finds "SECAM 50" and "SECAM-50"
|
{ R"([ _\-(\[<]+SECAM[ _\-)\]>]?)", "SECAM" }
|
||||||
};
|
}};
|
||||||
string filename = myOSystem.romFile().getNameWithExt(""); // get filename *without* extension
|
|
||||||
|
|
||||||
for (const auto& item : Pattern)
|
// Get filename *without* extension, and search using regex's above
|
||||||
|
const string& filename = myOSystem.romFile().getNameWithExt("");
|
||||||
|
for(size_t i = 0; i < Pattern.size(); ++i)
|
||||||
{
|
{
|
||||||
size_t pos = filename.find(item.first);
|
try
|
||||||
if (pos != string::npos)
|
|
||||||
{
|
{
|
||||||
// avoid false positives
|
std::regex rgx(Pattern[i][0]);
|
||||||
if (pos == filename.length() - (item.first).length() || // pattern at the very end
|
if(std::regex_search(filename, rgx))
|
||||||
((pos == 0 || isWhiteSpace(filename.at(pos - 1))) && // pattern within withspaces
|
return Pattern[i][1];
|
||||||
isWhiteSpace(filename.at(pos + (item.first).length()))))
|
}
|
||||||
return item.second;
|
catch(...)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// nothing found
|
|
||||||
|
// Nothing found
|
||||||
return "AUTO";
|
return "AUTO";
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
bool Console::isWhiteSpace(const char s) const
|
|
||||||
{
|
|
||||||
const string WHITESPACES = " _-()[]<>";
|
|
||||||
|
|
||||||
for (size_t i = 0; i < WHITESPACES.length(); ++i)
|
|
||||||
if (s == WHITESPACES[i])
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool Console::save(Serializer& out) const
|
bool Console::save(Serializer& out) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -348,13 +348,6 @@ class Console : public Serializable, public ConsoleIO
|
||||||
*/
|
*/
|
||||||
string formatFromFilename() const;
|
string formatFromFilename() const;
|
||||||
|
|
||||||
/**
|
|
||||||
Check if the given character is a whitespace.
|
|
||||||
@param s Character to check
|
|
||||||
@return True if whitespace character
|
|
||||||
*/
|
|
||||||
bool isWhiteSpace(const char s) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create the audio queue
|
Create the audio queue
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue