summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2016-08-13 01:00:52 +1000
committer GitHub <noreply@github.com>2016-08-13 01:00:52 +1000
commit41e4133d0bea0b0cbef328ce285fbf9e628e5093 (patch)
treed7e357a4f9cac8d11cca5fb1bdb7209a4b778263
parentb966180061af0c4702bac7eab75b2c357e4d0085 (diff)
parent9f5325a31145baa173c90d2f3b08ac363b4f53a5 (diff)
Merge pull request #1222 from npwoods/move_software_name_parsing
device_image_interface::software_name_split() ==> softlist.cpp:software_name_parse()
-rw-r--r--src/emu/diimage.cpp50
-rw-r--r--src/emu/diimage.h1
-rw-r--r--src/emu/image.cpp10
-rw-r--r--src/emu/softlist.cpp72
-rw-r--r--src/emu/softlist.h5
5 files changed, 81 insertions, 57 deletions
diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp
index 97c9559e9a9..d4d2be3d4b5 100644
--- a/src/emu/diimage.cpp
+++ b/src/emu/diimage.cpp
@@ -1255,53 +1255,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;
diff --git a/src/emu/diimage.h b/src/emu/diimage.h
index d2ea51c47e7..aac698230b8 100644
--- a/src/emu/diimage.h
+++ b/src/emu/diimage.h
@@ -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))
diff --git a/src/emu/image.cpp b/src/emu/image.cpp
index 5fbc5844b9d..06998ad37e6 100644
--- a/src/emu/image.cpp
+++ b/src/emu/image.cpp
@@ -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
diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp
index d7a8b8d86d8..6ae687db843 100644
--- a/src/emu/softlist.cpp
+++ b/src/emu/softlist.cpp
@@ -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;
+}
+
+
diff --git a/src/emu/softlist.h b/src/emu/softlist.h
index 6f3b69deaa7..d38779afe5d 100644
--- a/src/emu/softlist.h
+++ b/src/emu/softlist.h
@@ -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_