diff options
Diffstat (limited to 'src/lib/netlist/plib/pstring.cpp')
-rw-r--r-- | src/lib/netlist/plib/pstring.cpp | 120 |
1 files changed, 51 insertions, 69 deletions
diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp index c304f11d1fd..7d5d5a7dbc7 100644 --- a/src/lib/netlist/plib/pstring.cpp +++ b/src/lib/netlist/plib/pstring.cpp @@ -1,113 +1,89 @@ -// license:GPL-2.0+ +// license:BSD-3-Clause // copyright-holders:Couriersud -/* - * nl_string.c - * - */ #include "pstring.h" #include "palloc.h" -#include "plists.h" #include <algorithm> #include <atomic> #include <stack> template<typename F> -int pstring_t<F>::compare(const pstring_t &right) const +int pstring_t<F>::compare(const pstring_t &right) const noexcept { - if (mem_t_size() == 0 && right.mem_t_size() == 0) - return 0; - else if (right.mem_t_size() == 0) - return 1; - else if (mem_t_size() == 0) - return -1; - +#if 0 + return m_str.compare(right.m_str); +#else auto si = this->begin(); auto ri = right.begin(); - while (si != this->end() && ri != right.end() && *si == *ri) + const auto se = this->end(); + const auto re = right.end(); + + while (si != se && ri != re && *si == *ri) { - ri++; - si++; + ++ri; + ++si; } - if (si != this->end() && ri != right.end()) - return static_cast<int>(*si) - static_cast<int>(*ri); - else if (this->mem_t_size() > right.mem_t_size()) + if (si != se && ri != re) + return plib::narrow_cast<int>(*si) - plib::narrow_cast<int>(*ri); + if (si != se) return 1; - else if (this->mem_t_size() < right.mem_t_size()) + if (ri != re) return -1; return 0; +#endif } template<typename F> pstring_t<F> pstring_t<F>::substr(size_type start, size_type nlen) const { pstring_t ret; + auto ps = begin(); + while (ps != end() && start > 0) + { + ++ps; + --start; + } //FIXME: throw ? - const size_type l = length(); - if (start < l) + if (ps != end()) { - if (nlen == npos || start + nlen > l) - nlen = l - start; - auto ps = std::next(begin(), static_cast<difference_type>(start)); - auto pe = std::next(ps, static_cast<difference_type>(nlen)); + auto pe = ps; + while (pe != end() && nlen > 0) + { + ++pe; + --nlen; + } ret.m_str.assign(ps.p, pe.p); } return ret; } template<typename F> -typename pstring_t<F>::size_type pstring_t<F>::find_first_not_of(const pstring_t &no) const +pstring_t<F> pstring_t<F>::substr(size_type start) const { - size_type pos = 0; - for (auto it = begin(); it != end(); ++it, ++pos) + pstring_t ret; + auto ps = begin(); + while (ps != end() && start > 0) { - bool f = true; - for (code_t const jt : no) - { - if (*it == jt) - { - f = false; - break; - } - } - if (f) - return pos; + ++ps; + --start; } - return npos; -} - -template<typename F> -typename pstring_t<F>::size_type pstring_t<F>::find_last_not_of(const pstring_t &no) const -{ - /* FIXME: reverse iterator */ - size_type last_found = npos; - size_type pos = 0; - for (auto it = begin(); it != end(); ++it, ++pos) + //FIXME: throw ? + if (ps != end()) { - bool f = true; - for (code_t const jt : no) - { - if (*it == jt) - { - f = false; - break; - } - } - if (f) - last_found = pos; + ret.m_str.assign(ps.p, end().p); } - return last_found; + return ret; } template<typename F> -typename pstring_t<F>::size_type pstring_t<F>::find(const pstring_t &search, size_type start) const +typename pstring_t<F>::size_type pstring_t<F>::find(const pstring_t &search, size_type start) const noexcept { auto istart = std::next(begin(), static_cast<difference_type>(start)); for (; istart != end(); ++istart) { - auto itc(istart); + auto itc = istart; auto cmp = search.begin(); while (itc != end() && cmp != search.end() && *itc == *cmp) { @@ -122,11 +98,16 @@ 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 +typename pstring_t<F>::size_type pstring_t<F>::find(code_t search, size_type start) const noexcept { - pstring_t ss; - traits_type::encode(search, ss.m_str); - return find(ss, start); + auto i = std::next(begin(), static_cast<difference_type>(start)); + for (; i != end(); ++i) + { + if (*i == search) + return start; + ++start; + } + return npos; } // ---------------------------------------------------------------------------------------- @@ -136,4 +117,5 @@ typename pstring_t<F>::size_type pstring_t<F>::find(code_t search, size_type sta template struct pstring_t<pu8_traits>; template struct pstring_t<putf8_traits>; template struct pstring_t<putf16_traits>; +template struct pstring_t<putf32_traits>; template struct pstring_t<pwchar_traits>; |