Merge pull request #1222 from npwoods/move_software_name_parsing

device_image_interface::software_name_split() ==> softlist.cpp:software_name_parse()
This commit is contained in:
Vas Crabb 2016-08-13 01:00:52 +10:00 committed by GitHub
commit 41e4133d0b
5 changed files with 81 additions and 57 deletions

View File

@ -1254,53 +1254,6 @@ void device_image_interface::update_names(const device_type device_type, const c
}
}
//-------------------------------------------------
// software_name_split - helper that splits a
// software_list:software:part string into
// separate software_list, software, and part
// strings.
//
// str1:str2:str3 => swlist_name - str1, swname - str2, swpart - str3
// str1:str2 => swlist_name - nullptr, swname - str1, swpart - str2
// str1 => swlist_name - nullptr, swname - str1, swpart - nullptr
//
// Notice however that we could also have been
// passed a string swlist_name:swname, and thus
// some special check has to be performed in this
// case.
//-------------------------------------------------
void device_image_interface::software_name_split(const std::string &swlist_swname, std::string &swlist_name, std::string &swname, std::string &swpart)
{
// reset all output parameters
swlist_name.clear();
swname.clear();
swpart.clear();
// if no colon, this is the swname by itself
auto split1 = swlist_swname.find_first_of(':');
if (split1 == std::string::npos)
{
swname = swlist_swname;
return;
}
// if one colon, it is the swname and swpart alone
auto split2 = swlist_swname.find_first_of(':', split1 + 1);
if (split2 == std::string::npos)
{
swname = swlist_swname.substr(0, split1);
swpart = swlist_swname.substr(split1 + 1);
return;
}
// if two colons present, split into 3 parts
swlist_name = swlist_swname.substr(0, split1);
swname = swlist_swname.substr(split1 + 1, split2 - (split1 + 1));
swpart = swlist_swname.substr(split2 + 1);
}
//-------------------------------------------------
// find_software_item
//-------------------------------------------------
@ -1309,7 +1262,8 @@ const software_part *device_image_interface::find_software_item(const std::strin
{
// split full software name into software list name and short software name
std::string swlist_name, swinfo_name, swpart_name;
software_name_split(path, swlist_name, swinfo_name, swpart_name);
if (!software_name_parse(path, &swlist_name, &swinfo_name, &swpart_name))
return nullptr;
// determine interface
const char *interface = nullptr;

View File

@ -238,7 +238,6 @@ public:
bool load_software(software_list_device &swlist, const char *swname, const rom_entry *entry);
int reopen_for_write(const std::string &path);
static void software_name_split(const std::string &swlist_swname, std::string &swlist_name, std::string &swname, std::string &swpart);
static void static_set_user_loadable(device_t &device, bool user_loadable) {
device_image_interface *img;
if (!device.interface(img))

View File

@ -10,19 +10,13 @@
***************************************************************************/
#include <ctype.h>
#include <regex>
#include "emu.h"
#include "emuopts.h"
#include "image.h"
#include "config.h"
#include "xmlfile.h"
//**************************************************************************
// STATIC VARIABLES
//**************************************************************************
static std::regex s_potenial_softlist_regex("\\w+(\\:\\w+\\:\\w+)?");
#include "softlist.h"
//**************************************************************************
@ -54,7 +48,7 @@ image_manager::image_manager(running_machine &machine)
image.set_init_phase();
// try as a softlist
if (std::regex_match(image_name, s_potenial_softlist_regex))
if (software_name_parse(image_name))
result = image.load_software(image_name);
// failing that, try as an image

View File

@ -8,10 +8,20 @@
***************************************************************************/
#include <regex>
#include "softlist.h"
#include "hash.h"
#include "expat.h"
//**************************************************************************
// STATIC VARIABLES
//**************************************************************************
static std::regex s_potenial_softlist_regex("\\w+(\\:\\w+)*");
//**************************************************************************
// FEATURE LIST ITEM
//**************************************************************************
@ -808,3 +818,65 @@ void softlist_parser::parse_soft_end(const char *tagname)
}
}
//-------------------------------------------------
// software_name_parse - helper that splits a
// software_list:software:part string into
// separate software_list, software, and part
// strings.
//
// str1:str2:str3 => swlist_name - str1, swname - str2, swpart - str3
// str1:str2 => swlist_name - nullptr, swname - str1, swpart - str2
// str1 => swlist_name - nullptr, swname - str1, swpart - nullptr
//
// Notice however that we could also have been
// passed a string swlist_name:swname, and thus
// some special check has to be performed in this
// case.
//-------------------------------------------------
bool software_name_parse(const std::string &text, std::string *swlist_name, std::string *swname, std::string *swpart)
{
// first, sanity check the arguments
if (!std::regex_match(text, s_potenial_softlist_regex))
return false;
// reset all output parameters (if specified of course)
if (swlist_name != nullptr)
swlist_name->clear();
if (swname != nullptr)
swname->clear();
if (swpart != nullptr)
swpart->clear();
// if no colon, this is the swname by itself
auto split1 = text.find_first_of(':');
if (split1 == std::string::npos)
{
if (swname != nullptr)
*swname = text;
return true;
}
// if one colon, it is the swname and swpart alone
auto split2 = text.find_first_of(':', split1 + 1);
if (split2 == std::string::npos)
{
if (swname != nullptr)
*swname = text.substr(0, split1);
if (swpart != nullptr)
*swpart = text.substr(split1 + 1);
return true;
}
// if two colons present, split into 3 parts
if (swlist_name != nullptr)
*swlist_name = text.substr(0, split1);
if (swname != nullptr)
*swname = text.substr(split1 + 1, split2 - (split1 + 1));
if (swpart != nullptr)
*swpart = text.substr(split2 + 1);
return true;
}

View File

@ -205,5 +205,10 @@ private:
};
// ----- Helpers -----
// parses a software name (e.g. - 'apple2e:agentusa:flop1') into its consituent parts (returns false if cannot parse)
bool software_name_parse(const std::string &text, std::string *swlist_name = nullptr, std::string *swname = nullptr, std::string *swpart = nullptr);
#endif // __SOFTLIST_H_