mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Add additional find test case. Change test to pos <= size(), thus avoiding unneeded call to std::search. Add missing signatures.
This commit is contained in:
parent
6c5a955c85
commit
24933c4409
@ -211,7 +211,7 @@ namespace boost {
|
|||||||
|
|
||||||
// find
|
// find
|
||||||
/*BOOST_CONSTEXPR*/ size_type find(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
|
/*BOOST_CONSTEXPR*/ size_type find(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
|
||||||
if (s.empty() && pos == size())
|
if (s.empty() && pos <= size())
|
||||||
return pos;
|
return pos;
|
||||||
if (pos > size())
|
if (pos > size())
|
||||||
return npos;
|
return npos;
|
||||||
@ -219,15 +219,12 @@ namespace boost {
|
|||||||
s.cbegin (), s.cend (), traits::eq );
|
s.cbegin (), s.cend (), traits::eq );
|
||||||
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
||||||
}
|
}
|
||||||
BOOST_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT {
|
BOOST_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT
|
||||||
return find(basic_string_view(&c, 1), pos);
|
{ return find(basic_string_view(&c, 1), pos); }
|
||||||
}
|
BOOST_CONSTEXPR size_type find(const charT* s, size_type pos, size_type n) const
|
||||||
BOOST_CONSTEXPR size_type find(const charT* s, size_type pos, size_type n) const {
|
{ return find(basic_string_view(s, n), pos); }
|
||||||
return find(basic_string_view(s, n), pos);
|
BOOST_CONSTEXPR size_type find(const charT* s, size_type pos = 0) const
|
||||||
}
|
{ return find(basic_string_view(s), pos); }
|
||||||
BOOST_CONSTEXPR size_type find(const charT* s, size_type pos = 0) const {
|
|
||||||
return find(basic_string_view(s), pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// rfind
|
// rfind
|
||||||
BOOST_CONSTEXPR size_type rfind(basic_string_view s, size_type pos = npos)
|
BOOST_CONSTEXPR size_type rfind(basic_string_view s, size_type pos = npos)
|
||||||
@ -236,54 +233,62 @@ namespace boost {
|
|||||||
s.crbegin (), s.crend (), traits::eq );
|
s.crbegin (), s.crend (), traits::eq );
|
||||||
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
|
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
|
||||||
}
|
}
|
||||||
|
BOOST_CONSTEXPR size_type rfind(charT c, size_type pos = npos) const BOOST_NOEXCEPT
|
||||||
BOOST_CONSTEXPR size_type rfind(charT c) const BOOST_NOEXCEPT {
|
{ return rfind(basic_string_view(&c, 1), pos); }
|
||||||
const_reverse_iterator iter = std::find_if ( this->crbegin (), this->crend (),
|
BOOST_CONSTEXPR size_type rfind(const charT* s, size_type pos, size_type n) const
|
||||||
detail::string_view_traits_eq<charT, traits> ( c ));
|
{ return rfind(basic_string_view(s, n), pos); }
|
||||||
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
|
BOOST_CONSTEXPR size_type rfind(const charT* s, size_type pos = npos) const
|
||||||
}
|
{ return rfind(basic_string_view(s), pos); }
|
||||||
|
|
||||||
// find_first_of
|
// find_first_of
|
||||||
BOOST_CONSTEXPR size_type find_first_of(basic_string_view s) const BOOST_NOEXCEPT {
|
BOOST_CONSTEXPR size_type find_first_of(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
|
||||||
const_iterator iter = std::find_first_of
|
const_iterator iter = std::find_first_of
|
||||||
( this->cbegin (), this->cend (), s.cbegin (), s.cend (), traits::eq );
|
( this->cbegin (), this->cend (), s.cbegin (), s.cend (), traits::eq );
|
||||||
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
||||||
}
|
}
|
||||||
BOOST_CONSTEXPR size_type find_first_of(charT c) const BOOST_NOEXCEPT { return find (c); }
|
BOOST_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); }
|
||||||
|
BOOST_CONSTEXPR size_type find_first_of(const charT* s, size_type pos, size_type n) const
|
||||||
|
{ return find_first_of(basic_string_view(s, n), pos); }
|
||||||
|
BOOST_CONSTEXPR size_type find_first_of(const charT* s, size_type pos = 0) const
|
||||||
|
{ return find_first_of(basic_string_view(s), pos); }
|
||||||
|
|
||||||
// find_last_of
|
// find_last_of
|
||||||
BOOST_CONSTEXPR size_type find_last_of(basic_string_view s) const BOOST_NOEXCEPT {
|
BOOST_CONSTEXPR size_type find_last_of(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
|
||||||
const_reverse_iterator iter = std::find_first_of
|
const_reverse_iterator iter = std::find_first_of
|
||||||
( this->crbegin (), this->crend (), s.cbegin (), s.cend (), traits::eq );
|
( this->crbegin (), this->crend (), s.cbegin (), s.cend (), traits::eq );
|
||||||
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter);
|
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter);
|
||||||
}
|
}
|
||||||
BOOST_CONSTEXPR size_type find_last_of (charT c) const BOOST_NOEXCEPT { return rfind (c); }
|
BOOST_CONSTEXPR size_type find_last_of(charT c, size_type pos = npos) const BOOST_NOEXCEPT
|
||||||
|
{ return find_last_of(basic_string_view(&c, 1), pos); }
|
||||||
|
BOOST_CONSTEXPR size_type find_last_of(const charT* s, size_type pos, size_type n) const
|
||||||
|
{ return find_last_of(basic_string_view(s, n), pos); }
|
||||||
|
BOOST_CONSTEXPR size_type find_last_of(const charT* s, size_type pos = npos) const
|
||||||
|
{ return find_last_of(basic_string_view(s), pos); }
|
||||||
|
|
||||||
// find_first_not_of
|
// find_first_not_of
|
||||||
BOOST_CONSTEXPR size_type find_first_not_of(basic_string_view s) const {
|
BOOST_CONSTEXPR size_type find_first_not_of(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
|
||||||
const_iterator iter = find_not_of ( this->cbegin (), this->cend (), s );
|
const_iterator iter = find_not_of ( this->cbegin (), this->cend (), s );
|
||||||
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
||||||
}
|
}
|
||||||
|
BOOST_CONSTEXPR size_type find_first_not_of(charT c, size_type pos = 0) const BOOST_NOEXCEPT
|
||||||
BOOST_CONSTEXPR size_type find_first_not_of(charT c) const BOOST_NOEXCEPT {
|
{ return find_first_not_of(basic_string_view(&c, 1), pos); }
|
||||||
for ( const_iterator iter = this->cbegin (); iter != this->cend (); ++iter )
|
BOOST_CONSTEXPR size_type find_first_not_of(const charT* s, size_type pos, size_type n) const
|
||||||
if ( !traits::eq ( c, *iter ))
|
{ return find_first_not_of(basic_string_view(s, n), pos); }
|
||||||
return std::distance ( this->cbegin (), iter );
|
BOOST_CONSTEXPR size_type find_first_not_of(const charT* s, size_type pos = 0) const
|
||||||
return npos;
|
{ return find_first_not_of(basic_string_view(s), pos); }
|
||||||
}
|
|
||||||
|
|
||||||
// find_last_not_of
|
// find_last_not_of
|
||||||
BOOST_CONSTEXPR size_type find_last_not_of(basic_string_view s) const BOOST_NOEXCEPT {
|
BOOST_CONSTEXPR size_type find_last_not_of(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
|
||||||
const_reverse_iterator iter = find_not_of ( this->crbegin (), this->crend (), s );
|
const_reverse_iterator iter = find_not_of ( this->crbegin (), this->crend (), s );
|
||||||
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
|
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
|
||||||
}
|
}
|
||||||
|
BOOST_CONSTEXPR size_type find_last_not_of(charT c, size_type pos = npos) const BOOST_NOEXCEPT
|
||||||
BOOST_CONSTEXPR size_type find_last_not_of(charT c) const BOOST_NOEXCEPT {
|
{ return find_last_not_of(basic_string_view(&c, 1), pos); }
|
||||||
for ( const_reverse_iterator iter = this->crbegin (); iter != this->crend (); ++iter )
|
BOOST_CONSTEXPR size_type find_last_not_of(const charT* s, size_type pos, size_type n) const
|
||||||
if ( !traits::eq ( c, *iter ))
|
{ return find_last_not_of(basic_string_view(s, n), pos); }
|
||||||
return reverse_distance ( this->crbegin (), iter );
|
BOOST_CONSTEXPR size_type find_last_not_of(const charT* s, size_type pos = npos) const
|
||||||
return npos;
|
{ return find_last_not_of(basic_string_view(s), pos); }
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename r_iter>
|
template <typename r_iter>
|
||||||
|
@ -34,6 +34,8 @@ namespace
|
|||||||
BOOST_TEST_EQ(sv2.find(sv3), s2.find(s3));
|
BOOST_TEST_EQ(sv2.find(sv3), s2.find(s3));
|
||||||
BOOST_TEST_EQ(sv3.find(sv2), s3.find(s2));
|
BOOST_TEST_EQ(sv3.find(sv2), s3.find(s2));
|
||||||
BOOST_TEST_EQ(sv1.find(sv3, 7), s1.find(s3, 7));
|
BOOST_TEST_EQ(sv1.find(sv3, 7), s1.find(s3, 7));
|
||||||
|
BOOST_TEST_EQ(sv1.find(sv3, 5), s1.find(s3, 5));
|
||||||
|
//std::cout << s1.find(s3, 5) << std::endl;
|
||||||
|
|
||||||
BOOST_TEST_EQ(sv1.find(sv2), s1.find(s2));
|
BOOST_TEST_EQ(sv1.find(sv2), s1.find(s2));
|
||||||
for (std::string::size_type i = 0; i <= 8; ++i)
|
for (std::string::size_type i = 0; i <= 8; ++i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user