From b380514764cf857469bae61c11143a19f79a74c5 Mon Sep 17 00:00:00 2001 From: andreasnaive Date: Mon, 25 Mar 2019 23:13:40 +0100 Subject: Revert "conflict resolution (nw)" This reverts commit c24473ddff715ecec2e258a6eb38960cf8c8e98e, reversing changes made to 009cba4fb8102102168ef32870892438327f3705. --- src/lib/netlist/plib/pstring.cpp | 131 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) (limited to 'src/lib/netlist/plib/pstring.cpp') diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp index c304f11d1fd..47d35d7c82f 100644 --- a/src/lib/netlist/plib/pstring.cpp +++ b/src/lib/netlist/plib/pstring.cpp @@ -10,8 +10,17 @@ #include "plists.h" #include -#include #include +#include + +template +std::size_t strlen_mem(const T *s) +{ + std::size_t len(0); + while (*s++) + ++len; + return len; +} template int pstring_t::compare(const pstring_t &right) const @@ -57,6 +66,18 @@ pstring_t pstring_t::substr(size_type start, size_type nlen) const return ret; } +template +pstring_t pstring_t::ucase() const +{ + pstring_t ret; + for (const auto &c : *this) + if (c >= 'a' && c <= 'z') + ret += (c - 'a' + 'A'); + else + ret += c; + return ret; +} + template typename pstring_t::size_type pstring_t::find_first_not_of(const pstring_t &no) const { @@ -129,6 +150,114 @@ typename pstring_t::size_type pstring_t::find(code_t search, size_type sta return find(ss, start); } + +template +pstring_t pstring_t::replace_all(const pstring_t &search, const pstring_t &replace) const +{ + pstring_t ret; + const size_type slen = search.length(); + + size_type last_s = 0; + size_type s = find(search, last_s); + while (s != npos) + { + ret += substr(last_s, s - last_s); + ret += replace; + last_s = s + slen; + s = find(search, last_s); + } + ret += substr(last_s); + return ret; +} + +template +pstring_t pstring_t::rpad(const pstring_t &ws, const size_type cnt) const +{ + // FIXME: pstringbuffer ret(*this); + + pstring_t ret(*this); + size_type wsl = ws.length(); + for (auto i = ret.length(); i < cnt; i+=wsl) + ret += ws; + return ret; +} + +static double pstod(const pstring_t &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 &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 +double pstring_t::as_double(bool *error) const +{ + std::size_t e = 0; + if (error != nullptr) + *error = false; + double ret = pstod(*this, &e); + if (e != mem_t_size()) + if (error != nullptr) + *error = true; + return ret; +} + +template +long pstring_t::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(prefix)) + ret = pstol(substr(2), &e, 16); + else + ret = pstol(*this, &e, 10); + if (e != mem_t_size()) + if (error != nullptr) + *error = true; + return ret; +} + // ---------------------------------------------------------------------------------------- // template stuff ... // ---------------------------------------------------------------------------------------- -- cgit v1.2.3-70-g09d2