summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/putil.cpp
diff options
context:
space:
mode:
author Couriersud <couriersud@gmx.org>2020-09-05 19:43:54 +0200
committer Couriersud <couriersud@gmx.org>2020-09-05 21:31:49 +0200
commitf3eb6324652fea263972087146fbdde9e32f9a0f (patch)
treef63d352948c3a4fcf62857839cc5c5359804b0f5 /src/lib/netlist/plib/putil.cpp
parent4dd7e21f565b12e8487b884089d769f0b30147c6 (diff)
netlist: code maintenance and performance optimizations.
* rename some misleading type names * remove callback_t and replace by better scalable approach * hide implementations details * move sources classes from putil.h to psources.h * reduce code complexity * improve parsing performance, parsing netlists now is twice as fast. * fix issues around multi-byte string support * moved psplit into pstrutil.h
Diffstat (limited to 'src/lib/netlist/plib/putil.cpp')
-rw-r--r--src/lib/netlist/plib/putil.cpp105
1 files changed, 6 insertions, 99 deletions
diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp
index 60eab248c9d..b86431633d1 100644
--- a/src/lib/netlist/plib/putil.cpp
+++ b/src/lib/netlist/plib/putil.cpp
@@ -8,7 +8,7 @@
#include "ptypes.h"
#include <algorithm>
-#include <cstdlib> // needed for getenv ...
+// needed for getenv ...
#include <initializer_list>
namespace plib
@@ -59,109 +59,16 @@ namespace plib
pstring environment(const pstring &var, const pstring &default_val)
{
- return (std::getenv(var.c_str()) == nullptr) ? default_val
- : pstring(std::getenv(var.c_str()));
+ putf8string varu8(var);
+ return (std::getenv(varu8.c_str()) == nullptr) ? default_val
+ : pstring(std::getenv(varu8.c_str()));
}
} // namespace util
- std::vector<pstring> psplit(const pstring &str, const pstring &onstr, bool ignore_empty)
- {
- std::vector<pstring> ret;
-
- pstring::size_type p = 0;
- pstring::size_type pn = str.find(onstr, p);
-
- while (pn != pstring::npos)
- {
- pstring t = str.substr(p, pn - p);
- if (!ignore_empty || t.length() != 0)
- ret.push_back(t);
- p = pn + onstr.length();
- pn = str.find(onstr, p);
- }
- if (p < str.length())
- {
- pstring t = str.substr(p);
- if (!ignore_empty || t.length() != 0)
- ret.push_back(t);
- }
- return ret;
- }
-
- std::vector<std::string> psplit_r(const std::string &stri,
- const std::string &token,
- const std::size_t maxsplit)
- {
- std::string str(stri);
- std::vector<std::string> result;
- std::size_t splits = 0;
-
- while(!str.empty())
- {
- 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.empty())
- result.push_back(str);
- }
- else
- {
- result.push_back(str);
- str = "";
- }
- }
- return result;
- }
-
- std::vector<pstring> psplit(const pstring &str, const std::vector<pstring> &onstrl)
- {
- pstring col = "";
- std::vector<pstring> ret;
-
- auto i = str.begin();
- while (i != str.end())
- {
- auto p = pstring::npos;
- for (std::size_t j=0; j < onstrl.size(); j++)
- {
- if (std::equal(onstrl[j].begin(), onstrl[j].end(), i))
- {
- p = j;
- break;
- }
- }
- if (p != pstring::npos)
- {
- if (!col.empty())
- ret.push_back(col);
-
- col = "";
- ret.push_back(onstrl[p]);
- i = std::next(i, narrow_cast<pstring::difference_type>(onstrl[p].length()));
- }
- else
- {
- pstring::value_type c = *i;
- col += c;
- i++;
- }
- }
- if (!col.empty())
- ret.push_back(col);
-
- return ret;
- }
-
-
int penum_base::from_string_int(const pstring &str, const pstring &x)
{
int cnt = 0;
- for (auto &s : psplit(str, ",", false))
+ for (auto &s : psplit(str, ',', false))
{
if (trim(s) == x)
return cnt;
@@ -172,6 +79,6 @@ namespace plib
pstring penum_base::nthstr(std::size_t n, const pstring &str)
{
- return psplit(str, ",", false)[n];
+ return psplit(str, ',', false)[n];
}
} // namespace plib