From 97b67170277437131adf6ed4d60139c172529e4f Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 26 Mar 2019 11:13:37 +1100 Subject: (nw) Clean up the mess on master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This effectively reverts b380514764cf857469bae61c11143a19f79a74c5 and c24473ddff715ecec2e258a6eb38960cf8c8e98e, restoring the state at 598cd5227223c3b04ca31f0dbc1981256d9ea3ff. Before pushing, please check that what you're about to push is sane. Check your local commit log and ensure there isn't anything out-of-place before pushing to mainline. When things like this happen, it wastes everyone's time. I really don't need this in a week when real work™ is busting my balls and I'm behind where I want to be with preparing for MAME release. --- src/lib/netlist/plib/putil.cpp | 75 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 34 deletions(-) (limited to 'src/lib/netlist/plib/putil.cpp') diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp index c34102417ec..b62cbf60865 100644 --- a/src/lib/netlist/plib/putil.cpp +++ b/src/lib/netlist/plib/putil.cpp @@ -2,13 +2,13 @@ // copyright-holders:Couriersud #include "putil.h" -#include "ptypes.h" #include "plists.h" +#include "ptypes.h" -#include #include -#include +#include #include +#include namespace plib { @@ -17,7 +17,7 @@ namespace plib const pstring buildpath(std::initializer_list list ) { pstring ret = ""; - for( auto elem : list ) + for( const auto &elem : list ) { if (ret == "") ret = elem; @@ -33,12 +33,12 @@ namespace plib const pstring environment(const pstring &var, const pstring &default_val) { - if (getenv(var.c_str()) == nullptr) + if (std::getenv(var.c_str()) == nullptr) return default_val; else - return pstring(getenv(var.c_str()), pstring::UTF8); + return pstring(std::getenv(var.c_str())); } - } + } // namespace util std::vector psplit(const pstring &str, const pstring &onstr, bool ignore_empty) { @@ -64,6 +64,36 @@ namespace plib return ret; } + std::vector psplit_r(const std::string &stri, + const std::string &token, + const std::size_t maxsplit) + { + std::string str(stri); + std::vector result; + std::size_t splits = 0; + + while(str.size()) + { + std::size_t index = str.rfind(token); + bool found = index!=std::string::npos; + if (found) + splits++; + if ((splits <= maxsplit || maxsplit == 0) && found) + { + result.push_back(str.substr(index+token.size())); + str = str.substr(0, index); + if (str.size()==0) + result.push_back(str); + } + else + { + result.push_back(str); + str = ""; + } + } + return result; + } + std::vector psplit(const pstring &str, const std::vector &onstrl) { pstring col = ""; @@ -72,7 +102,7 @@ namespace plib auto i = str.begin(); while (i != str.end()) { - std::size_t p = static_cast(-1); + auto p = static_cast(-1); for (std::size_t j=0; j < onstrl.size(); j++) { if (std::equal(onstrl[j].begin(), onstrl[j].end(), i)) @@ -92,7 +122,7 @@ namespace plib } else { - pstring::code_t c = *i; + pstring::value_type c = *i; col += c; i++; } @@ -131,31 +161,8 @@ namespace plib return cnt; return -1; } - pstring penum_base::nthstr(int n, const char *str) + std::string penum_base::nthstr(int n, const char *str) { - char buf[64]; - char *bufp = buf; - int cur = 0; - while (*str) - { - if (cur == n) - { - if (*str == ',') - { - *bufp = 0; - return pstring(buf, pstring::UTF8); - } - else if (*str != ' ') - *bufp++ = *str; - } - else - { - if (*str == ',') - cur++; - } - str++; - } - *bufp = 0; - return pstring(buf, pstring::UTF8); + return psplit(str, ",", false)[static_cast(n)]; } } // namespace plib -- cgit v1.2.3-70-g09d2