summaryrefslogtreecommitdiff
path: root/boost/utility/string_view.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/utility/string_view.hpp')
-rw-r--r--boost/utility/string_view.hpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/boost/utility/string_view.hpp b/boost/utility/string_view.hpp
index 09d52d2d34..44efda97bf 100644
--- a/boost/utility/string_view.hpp
+++ b/boost/utility/string_view.hpp
@@ -245,12 +245,27 @@ namespace boost {
return npos;
if (s.empty())
return pos;
- const_iterator iter = std::search(this->cbegin() + pos, this->cend(),
- s.cbegin (), s.cend (), traits::eq);
- return iter == this->cend () ? npos : std::distance(this->cbegin (), iter);
+ if (s.size() > size() - pos)
+ return npos;
+ const charT* cur = ptr_ + pos;
+ const charT* last = cend() - s.size() + 1;
+ for (; cur != last ; ++cur) {
+ cur = traits::find(cur, last - cur, s[0]);
+ if (!cur)
+ return npos;
+ if (traits::compare(cur, s.cbegin(), s.size()) == 0)
+ return cur - ptr_;
+ }
+ return npos;
+ }
+ BOOST_CXX14_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT {
+ if (pos > size())
+ return npos;
+ const charT* ret_ptr = traits::find(ptr_ + pos, len_ - pos, c);
+ if (ret_ptr)
+ return ret_ptr - ptr_;
+ return npos;
}
- BOOST_CXX14_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT
- { return find(basic_string_view(&c, 1), pos); }
BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
{ return find(basic_string_view(s, n), pos); }
BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
@@ -287,7 +302,7 @@ namespace boost {
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
}
BOOST_CXX14_CONSTEXPR size_type find_first_of(charT c, size_type pos = 0) const BOOST_NOEXCEPT
- { return find_first_of(basic_string_view(&c, 1), pos); }
+ { return find(c, pos); }
BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
{ return find_first_of(basic_string_view(s, n), pos); }
BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT