From 1415421fd707ad02e0cfddf20bf70bbd045a9203 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 6 Jan 2019 13:17:20 +0100 Subject: More c++ alignment. pstring now behaves like std::string. (nw) This change removes all string extensions like trim, rpad, left, right, ... from pstring and replaces them by function templates. This aligns a lot better with the intentions of the standard library. --- src/lib/netlist/plib/pstring.cpp | 120 --------------------------------------- 1 file changed, 120 deletions(-) (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 47d35d7c82f..9db4a77efe3 100644 --- a/src/lib/netlist/plib/pstring.cpp +++ b/src/lib/netlist/plib/pstring.cpp @@ -66,18 +66,6 @@ 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 { @@ -150,114 +138,6 @@ 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