summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pstring.cpp
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2017-03-31 18:07:35 +0200
committer couriersud <couriersud@gmx.org>2017-04-04 02:02:56 +0200
commit58aa97913fa966b03d3b5bed77c6670e49821f1e (patch)
tree22aa0c6d2a40ed4a751226ae33d28db6ae149be3 /src/lib/netlist/plib/pstring.cpp
parent9e78adc115a11d4495d291b10d5177a9d06d62f2 (diff)
pstring, pdynlib, pfmtlog refactoring :
pstring: - added support for UTF16LE to pstring. - renamed size() to mem_t_size() - renmaed len() to length() - added size() == length() - added empty() - added simple compare() pfmtlog: - Simplified pfmtlog, added more c++ pdynlib: - add a dynproc type to dynlib to wrap dynamic library calls. various: - fix two coverty scan issue. - various clang warnings fixed. (nw)
Diffstat (limited to 'src/lib/netlist/plib/pstring.cpp')
-rw-r--r--src/lib/netlist/plib/pstring.cpp94
1 files changed, 68 insertions, 26 deletions
diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp
index 0fa6a6f83d9..554baac9bc7 100644
--- a/src/lib/netlist/plib/pstring.cpp
+++ b/src/lib/netlist/plib/pstring.cpp
@@ -23,14 +23,14 @@ std::size_t strlen_mem(const T *s)
}
template<typename F>
-int pstring_t<F>::pcmp(const pstring_t &right) const
+int pstring_t<F>::compare(const pstring_t &right) const
{
- std::size_t l = std::min(size(), right.size());
+ std::size_t l = std::min(mem_t_size(), right.mem_t_size());
if (l == 0)
{
- if (size() == 0 && right.size() == 0)
+ if (mem_t_size() == 0 && right.mem_t_size() == 0)
return 0;
- else if (right.size() == 0)
+ else if (right.mem_t_size() == 0)
return 1;
else
return -1;
@@ -45,9 +45,9 @@ int pstring_t<F>::pcmp(const pstring_t &right) const
int ret = (si == this->end() ? 0 : static_cast<int>(*si) - static_cast<int>(*ri));
if (ret == 0)
{
- if (this->size() > right.size())
+ if (this->mem_t_size() > right.mem_t_size())
ret = 1;
- else if (this->size() < right.size())
+ else if (this->mem_t_size() < right.mem_t_size())
ret = -1;
}
return ret;
@@ -58,7 +58,7 @@ pstring_t<F> pstring_t<F>::substr(size_type start, size_type nlen) const
{
pstring_t ret;
//FIXME: throw ?
- const size_type l = len();
+ const size_type l = length();
if (start < l)
{
if (nlen == npos || start + nlen > l)
@@ -73,7 +73,7 @@ pstring_t<F> pstring_t<F>::substr(size_type start, size_type nlen) const
template<typename F>
pstring_t<F> pstring_t<F>::ucase() const
{
- pstring_t ret = "";
+ pstring_t ret;
for (const auto &c : *this)
if (c >= 'a' && c <= 'z')
ret += (c - 'a' + 'A');
@@ -149,17 +149,17 @@ typename pstring_t<F>::size_type pstring_t<F>::find(const pstring_t &search, siz
template<typename F>
typename pstring_t<F>::size_type pstring_t<F>::find(code_t search, size_type start) const
{
- mem_t buf[traits_type::MAXCODELEN+1] = { 0 };
- traits_type::encode(search, buf);
- return find(pstring_t(&buf[0], UTF8), start);
+ pstring_t ss;
+ traits_type::encode(search, ss.m_str);
+ return find(ss, start);
}
template<typename F>
pstring_t<F> pstring_t<F>::replace_all(const pstring_t &search, const pstring_t &replace) const
{
- pstring_t ret("");
- const size_type slen = search.len();
+ pstring_t ret;
+ const size_type slen = search.length();
size_type last_s = 0;
size_type s = find(search, last_s);
@@ -180,22 +180,64 @@ pstring_t<F> pstring_t<F>::rpad(const pstring_t &ws, const size_type cnt) const
// FIXME: pstringbuffer ret(*this);
pstring_t ret(*this);
- size_type wsl = ws.len();
- for (auto i = ret.len(); i < cnt; i+=wsl)
+ size_type wsl = ws.length();
+ for (auto i = ret.length(); i < cnt; i+=wsl)
ret += ws;
return ret;
}
+static double pstod(const pstring_t<pu8_traits> &str, std::size_t *e)
+{
+ return std::stod(str.cpp_string(), e);
+}
+
+static double pstod(const pstring &str, std::size_t *e)
+{
+ return std::stod(str.cpp_string(), e);
+}
+
+static double pstod(const pwstring &str, std::size_t *e)
+{
+ return std::stod(str.cpp_string(), e);
+}
+
+static double pstod(const pu16string &str, std::size_t *e)
+{
+ pstring c;
+ c = str;
+ return std::stod(c.cpp_string(), e);
+}
+
+static long pstol(const pstring_t<pu8_traits> &str, std::size_t *e, int base = 10)
+{
+ return std::stol(str.cpp_string(), e, base);
+}
+
+static long pstol(const pstring &str, std::size_t *e, int base = 10)
+{
+ return std::stol(str.cpp_string(), e, base);
+}
+
+static long pstol(const pwstring &str, std::size_t *e, int base = 10)
+{
+ return std::stol(str.cpp_string(), e, base);
+}
+
+static long pstol(const pu16string &str, std::size_t *e, int base = 10)
+{
+ pstring c;
+ c = str;
+ return std::stol(c.cpp_string(), e, base);
+}
+
template<typename F>
double pstring_t<F>::as_double(bool *error) const
{
- double ret;
std::size_t e = 0;
-
if (error != nullptr)
*error = false;
- ret = std::stod(m_str, &e);
- if (e != size())
+ double ret = pstod(*this, &e);
+ if (e != mem_t_size())
if (error != nullptr)
*error = true;
return ret;
@@ -204,16 +246,17 @@ double pstring_t<F>::as_double(bool *error) const
template<typename F>
long pstring_t<F>::as_long(bool *error) const
{
+ static pstring_t prefix(pstring("0x"));
long ret;
std::size_t e = 0;
if (error != nullptr)
*error = false;
- if (startsWith("0x"))
- ret = std::stol(substr(2).m_str, &e, 16);
+ if (startsWith(prefix))
+ ret = pstol(substr(2), &e, 16);
else
- ret = std::stol(m_str, &e, 10);
- if (e != size())
+ ret = pstol(*this, &e, 10);
+ if (e != mem_t_size())
if (error != nullptr)
*error = true;
return ret;
@@ -225,6 +268,5 @@ long pstring_t<F>::as_long(bool *error) const
template struct pstring_t<pu8_traits>;
template struct pstring_t<putf8_traits>;
-
-const unsigned pu8_traits::MAXCODELEN;
-const unsigned putf8_traits::MAXCODELEN;
+template struct pstring_t<putf16_traits>;
+template struct pstring_t<pwchar_traits>;