diff options
author | 2019-11-10 04:08:29 +1100 | |
---|---|---|
committer | 2019-11-10 04:08:29 +1100 | |
commit | 13b1ebb1b4512ba808cdc5dfbdac61ed0d755d8c (patch) | |
tree | 0be119271371bb88d200c5ec598c189e88218e8d /src/emu/softlist.cpp | |
parent | 1b2acde80819ca6917c248e496725158ed4fe12e (diff) |
start putting noexcept on things that have no business throwing exceptions, starting with diimage. also fix a slight bug in the interface matching function for software list parts. (nw)
Diffstat (limited to 'src/emu/softlist.cpp')
-rw-r--r-- | src/emu/softlist.cpp | 78 |
1 files changed, 43 insertions, 35 deletions
diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp index 04302f6b514..690bb47415f 100644 --- a/src/emu/softlist.cpp +++ b/src/emu/softlist.cpp @@ -15,6 +15,7 @@ #include "expat.h" +#include <cstring> #include <regex> @@ -34,8 +35,8 @@ static std::regex s_potenial_softlist_regex("\\w+(\\:\\w+)*"); // feature_list_item - constructor //------------------------------------------------- -feature_list_item::feature_list_item(const std::string &name, const std::string &value) - : m_next(nullptr), +feature_list_item::feature_list_item(const std::string &name, const std::string &value) : + m_next(nullptr), m_name(name), m_value(value) { @@ -46,8 +47,8 @@ feature_list_item::feature_list_item(const std::string &name, const std::string // feature_list_item - constructor //------------------------------------------------- -feature_list_item::feature_list_item(std::string &&name, std::string &&value) - : m_next(nullptr), +feature_list_item::feature_list_item(std::string &&name, std::string &&value) : + m_next(nullptr), m_name(std::move(name)), m_value(std::move(value)) { @@ -62,11 +63,11 @@ feature_list_item::feature_list_item(std::string &&name, std::string &&value) // software_part - constructor //------------------------------------------------- -software_part::software_part(software_info &info, std::string &&name, std::string &&interface) - : m_next(nullptr), - m_info(info), - m_name(std::move(name)), - m_interface(std::move(interface)) +software_part::software_part(software_info &info, std::string &&name, std::string &&interface) : + m_next(nullptr), + m_info(info), + m_name(std::move(name)), + m_interface(std::move(interface)) { } @@ -76,13 +77,13 @@ software_part::software_part(software_info &info, std::string &&name, std::strin // feature, if specified //------------------------------------------------- -const char *software_part::feature(const std::string &feature_name) const +const char *software_part::feature(const std::string &feature_name) const noexcept { // scan the feature list for an entry matching feature_name and return the value auto iter = std::find_if( - m_featurelist.begin(), - m_featurelist.end(), - [&feature_name](const feature_list_item &feature) { return feature.name() == feature_name; }); + m_featurelist.begin(), + m_featurelist.end(), + [&feature_name] (const feature_list_item &feature) { return feature.name() == feature_name; }); return iter != m_featurelist.end() ? iter->value().c_str() @@ -95,18 +96,25 @@ const char *software_part::feature(const std::string &feature_name) const // an interface in the provided list //------------------------------------------------- -bool software_part::matches_interface(const char *interface_list) const +bool software_part::matches_interface(const char *interface_list) const noexcept { // if we have no interface, then we match by default if (m_interface.empty()) return true; - // copy the comma-delimited interface list and ensure it ends with a final comma - std::string interfaces = std::string(interface_list).append(","); - - // then add a comma to the end of our interface and return true if we find it in the list string - std::string our_interface = std::string(m_interface).append(","); - return (interfaces.find(our_interface) != -1); + // find our interface at the beginning of the list or immediately following a comma + while (true) + { + char const *const found(std::strstr(interface_list, m_interface.c_str())); + if (!found) + return false; + if (((found == interface_list) || (',' == found[-1])) && ((',' == found[m_interface.size()]) || !found[m_interface.size()])) + return true; + interface_list = std::strchr(interface_list, ','); + if (!interface_list) + return false; + ++interface_list; + } } @@ -118,10 +126,10 @@ bool software_part::matches_interface(const char *interface_list) const // software_info - constructor //------------------------------------------------- -software_info::software_info(std::string &&name, std::string &&parent, const std::string &supported) - : m_supported(SOFTWARE_SUPPORTED_YES), - m_shortname(std::move(name)), - m_parentname(std::move(parent)) +software_info::software_info(std::string &&name, std::string &&parent, const std::string &supported) : + m_supported(SOFTWARE_SUPPORTED_YES), + m_shortname(std::move(name)), + m_parentname(std::move(parent)) { // handle the supported flag if provided if (supported == "partial") @@ -184,17 +192,17 @@ bool software_info::has_multiple_parts(const char *interface) const // softlist_parser - constructor //------------------------------------------------- -softlist_parser::softlist_parser(util::core_file &file, const std::string &filename, std::string &description, std::list<software_info> &infolist, std::ostringstream &errors) - : m_file(file), - m_filename(filename), - m_infolist(infolist), - m_errors(errors), - m_done(false), - m_description(description), - m_data_accum_expected(false), - m_current_info(nullptr), - m_current_part(nullptr), - m_pos(POS_ROOT) +softlist_parser::softlist_parser(util::core_file &file, const std::string &filename, std::string &description, std::list<software_info> &infolist, std::ostringstream &errors) : + m_file(file), + m_filename(filename), + m_infolist(infolist), + m_errors(errors), + m_done(false), + m_description(description), + m_data_accum_expected(false), + m_current_info(nullptr), + m_current_part(nullptr), + m_pos(POS_ROOT) { // create the parser m_parser = XML_ParserCreate_MM(nullptr, nullptr, nullptr); |