summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/putil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/plib/putil.cpp')
-rw-r--r--src/lib/netlist/plib/putil.cpp75
1 files changed, 34 insertions, 41 deletions
diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp
index b62cbf60865..c34102417ec 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 "plists.h"
#include "ptypes.h"
+#include "plists.h"
-#include <algorithm>
#include <cstdlib>
-#include <cstring>
+#include <algorithm>
#include <initializer_list>
+#include <cstring>
namespace plib
{
@@ -17,7 +17,7 @@ namespace plib
const pstring buildpath(std::initializer_list<pstring> list )
{
pstring ret = "";
- for( const auto &elem : list )
+ for( auto elem : list )
{
if (ret == "")
ret = elem;
@@ -33,12 +33,12 @@ namespace plib
const pstring environment(const pstring &var, const pstring &default_val)
{
- if (std::getenv(var.c_str()) == nullptr)
+ if (getenv(var.c_str()) == nullptr)
return default_val;
else
- return pstring(std::getenv(var.c_str()));
+ return pstring(getenv(var.c_str()), pstring::UTF8);
}
- } // namespace util
+ }
std::vector<pstring> psplit(const pstring &str, const pstring &onstr, bool ignore_empty)
{
@@ -64,36 +64,6 @@ namespace plib
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.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<pstring> psplit(const pstring &str, const std::vector<pstring> &onstrl)
{
pstring col = "";
@@ -102,7 +72,7 @@ namespace plib
auto i = str.begin();
while (i != str.end())
{
- auto p = static_cast<std::size_t>(-1);
+ std::size_t p = static_cast<std::size_t>(-1);
for (std::size_t j=0; j < onstrl.size(); j++)
{
if (std::equal(onstrl[j].begin(), onstrl[j].end(), i))
@@ -122,7 +92,7 @@ namespace plib
}
else
{
- pstring::value_type c = *i;
+ pstring::code_t c = *i;
col += c;
i++;
}
@@ -161,8 +131,31 @@ namespace plib
return cnt;
return -1;
}
- std::string penum_base::nthstr(int n, const char *str)
+ pstring penum_base::nthstr(int n, const char *str)
{
- return psplit(str, ",", false)[static_cast<std::size_t>(n)];
+ 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);
}
} // namespace plib