mirror of
https://github.com/boostorg/static_string.git
synced 2025-07-29 12:07:42 +02:00
Better inside string check, and addtional tests for better coverage
This commit is contained in:
@ -320,7 +320,7 @@ insert(
|
||||
BOOST_FIXED_STRING_THROW(std::length_error{
|
||||
"size() + count > max_size()"});
|
||||
const bool inside = s <= &s_[size()] && s >= &s_[0];
|
||||
if (!inside || (inside && (&s[count - 1] < &s_[index])))
|
||||
if (!inside || (inside && ((s - s_) + count <= index)))
|
||||
{
|
||||
Traits::move(&s_[index + count], &s_[index], size() - index + 1);
|
||||
Traits::copy(&s_[index], s, count);
|
||||
@ -597,7 +597,7 @@ replace(
|
||||
const bool inside = s <= &s_[size()] && s >= &s_[0];
|
||||
if (inside && (s - &s_[0]) == pos && n1 == n2)
|
||||
return *this;
|
||||
if (!inside || (inside && (&s[n2 - 1] < &s_[pos])))
|
||||
if (!inside || (inside && ((s - s_) + n2 <= pos)))
|
||||
{
|
||||
// source outside
|
||||
Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1);
|
||||
|
@ -23,7 +23,7 @@ testS(const S& s, typename S::size_type pos, typename S::size_type n)
|
||||
if (pos <= s.size())
|
||||
{
|
||||
typename S::string_view_type str = s.substr(pos, n);
|
||||
typename S::size_type rlen = std::min(n, s.size() - pos);
|
||||
typename S::size_type rlen = (std::min)(n, s.size() - pos);
|
||||
return (S::traits_type::compare(s.data() + pos, str.data(), rlen) == 0);
|
||||
}
|
||||
else
|
||||
@ -319,6 +319,10 @@ testAssignment()
|
||||
BOOST_TEST(fixed_string<3>{}.assign(fixed_string<5>{"abc"}) == "abc");
|
||||
BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<5>{"abc"}) == "abc");
|
||||
BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<5>{"abc"}) == "abc");
|
||||
{
|
||||
fixed_string<3> s("***");
|
||||
BOOST_TEST(s.assign(s) == s);
|
||||
}
|
||||
BOOST_TEST_THROWS(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}), std::length_error);
|
||||
|
||||
// assign(fixed_string<M, CharT, Traits> const& s, size_type pos, size_type count = npos)
|
||||
@ -5685,6 +5689,10 @@ testReplace()
|
||||
fixed_string<20> fs2 = "0123456789";
|
||||
BOOST_TEST(fs2.replace(0, 10, fs2.data(), 5) == "01234");
|
||||
}
|
||||
{
|
||||
fixed_string<20> fs1 = "helloworld";
|
||||
BOOST_TEST(fs1.replace(4, 3, fs1.data() + 1, 3) == "hellellrld");
|
||||
}
|
||||
|
||||
// replace(size_type pos1, size_type n1, const basic_string& str);
|
||||
{
|
||||
|
Reference in New Issue
Block a user