forked from boostorg/static_string
Minor bug fixs for find and replace, more tests
This commit is contained in:
@ -1832,7 +1832,8 @@ public:
|
|||||||
starts_with(
|
starts_with(
|
||||||
string_view_type s) const noexcept
|
string_view_type s) const noexcept
|
||||||
{
|
{
|
||||||
return starts_with(s.data());
|
const size_type len = s.size();
|
||||||
|
return n_ >= len && !Traits::compare(s_, s.data(), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -1854,7 +1855,8 @@ public:
|
|||||||
ends_with(
|
ends_with(
|
||||||
string_view_type s) const noexcept
|
string_view_type s) const noexcept
|
||||||
{
|
{
|
||||||
return ends_with(s.data());
|
const size_type len = s.size();
|
||||||
|
return n_ >= len && !Traits::compare(s_ + (n_ - len), s.data(), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -597,9 +597,11 @@ replace(
|
|||||||
if (pos > size())
|
if (pos > size())
|
||||||
BOOST_FIXED_STRING_THROW(std::out_of_range{
|
BOOST_FIXED_STRING_THROW(std::out_of_range{
|
||||||
"pos > size()"});
|
"pos > size()"});
|
||||||
if ((size() - n1 + n2) > max_size())
|
if (size() - std::min(n1, size() - pos) >= max_size() - n2)
|
||||||
BOOST_FIXED_STRING_THROW(std::length_error{
|
BOOST_FIXED_STRING_THROW(std::length_error{
|
||||||
"size() - n1 + n2 > max_size()"});
|
"replaced string exceeds max_size()"});
|
||||||
|
if (pos + n1 >= size())
|
||||||
|
n1 = size() - pos;
|
||||||
const bool inside = s <= &s_[size()] && s >= &s_[0];
|
const bool inside = s <= &s_[size()] && s >= &s_[0];
|
||||||
if (inside && (s - &s_[0]) == pos && n1 == n2)
|
if (inside && (s - &s_[0]) == pos && n1 == n2)
|
||||||
return *this;
|
return *this;
|
||||||
@ -640,9 +642,11 @@ replace(
|
|||||||
if (pos > size())
|
if (pos > size())
|
||||||
BOOST_FIXED_STRING_THROW(std::out_of_range{
|
BOOST_FIXED_STRING_THROW(std::out_of_range{
|
||||||
"pos > size()"});
|
"pos > size()"});
|
||||||
if ((size() - n1 + n2) > max_size())
|
if (size() - std::min(n1, size() - pos) >= max_size() - n2)
|
||||||
BOOST_FIXED_STRING_THROW(std::length_error{
|
BOOST_FIXED_STRING_THROW(std::length_error{
|
||||||
"replaced string exceeds max_size()"});
|
"replaced string exceeds max_size()"});
|
||||||
|
if (pos + n1 >= size())
|
||||||
|
n1 = size() - pos;
|
||||||
Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1);
|
Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1);
|
||||||
Traits::assign(&s_[pos], n2, c);
|
Traits::assign(&s_[pos], n2, c);
|
||||||
n_ += (n2 - n1);
|
n_ += (n2 - n1);
|
||||||
@ -675,12 +679,12 @@ rfind(
|
|||||||
size_type n) const ->
|
size_type n) const ->
|
||||||
size_type
|
size_type
|
||||||
{
|
{
|
||||||
if (n > n_)
|
if (n_ < n)
|
||||||
return npos;
|
return npos;
|
||||||
if (n == 0)
|
|
||||||
return pos;
|
|
||||||
if (pos > n_ - n)
|
if (pos > n_ - n)
|
||||||
pos = n_ - n;
|
pos = n_ - n;
|
||||||
|
if (!n)
|
||||||
|
return pos;
|
||||||
for (auto sub = &s_[pos]; sub >= s_; --sub)
|
for (auto sub = &s_[pos]; sub >= s_; --sub)
|
||||||
if (!Traits::compare(sub, s, n))
|
if (!Traits::compare(sub, s, n))
|
||||||
return std::distance(s_, sub);
|
return std::distance(s_, sub);
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user