replace impl added

This commit is contained in:
Krystian Stasiowski
2019-10-18 20:50:42 -04:00
parent e2119bd662
commit c2c50054f9
2 changed files with 66 additions and 4 deletions

View File

@ -1303,7 +1303,14 @@ public:
} }
template<typename T> template<typename T>
#if GENERATING_DOCUMENTATION
fixed_string& fixed_string&
#else
typename std::enable_if<
std::is_convertible<T, string_view_type>::value &&
! std::is_convertible<T, CharT const*>::value,
fixed_string&>::type
#endif
replace( replace(
size_type pos1, size_type pos1,
size_type n1, size_type n1,
@ -1314,7 +1321,14 @@ public:
} }
template<typename T> template<typename T>
#if GENERATING_DOCUMENTATION
fixed_string& fixed_string&
#else
typename std::enable_if<
std::is_convertible<T, string_view_type>::value &&
! std::is_convertible<T, CharT const*>::value,
fixed_string&>::type
#endif
replace( replace(
size_type pos1, size_type pos1,
size_type n1, size_type n1,
@ -1340,7 +1354,7 @@ public:
size_type n1, size_type n1,
const CharT* s) const CharT* s)
{ {
return replace(pos, n, s, Traits::length(s)); return replace(pos, n1, s, Traits::length(s));
} }
// impl // impl
@ -1361,7 +1375,14 @@ public:
} }
template<typename T> template<typename T>
#if GENERATING_DOCUMENTATION
fixed_string& fixed_string&
#else
typename std::enable_if<
std::is_convertible<T, string_view_type>::value &&
! std::is_convertible<T, CharT const*>::value,
fixed_string&>::type
#endif
replace( replace(
const_iterator i1, const_iterator i1,
const_iterator i2, const_iterator i2,
@ -1413,9 +1434,9 @@ public:
fixed_string& fixed_string&
replace( replace(
const_iterator, const_iterator i1,
const_iterator, const_iterator i2,
std::initializer_list<CharT>) std::initializer_list<CharT> il)
{ {
return replace(i1, i2, il.begin(), il.size()); return replace(i1, i2, il.begin(), il.size());
} }

View File

@ -569,6 +569,47 @@ swap(fixed_string<M, CharT, Traits>& s)
Traits::copy(&s_[0], &tmp.s_[0], n_ + 1); Traits::copy(&s_[0], &tmp.s_[0], n_ + 1);
} }
auto
fixed_string<N, CharT, Traits>::
replace(
size_type pos,
size_type n1,
const CharT* s,
size_type n2) -> fixed_string<N, CharT, Traits>&
{
if (pos > size())
BOOST_THROW_EXCEPTION(std::out_of_range{
"pos > size()"});
if ((size() - n1 + n2) > max_size())
BOOST_THROW_EXCEPTION(std::length_error{
"replaced string exceeds max_size()"});
Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1);
Traits::copy(&s_[pos], s, n2);
n_ += (n2 - n1);
return *this;
}
template<std::size_t N, typename CharT, typename Traits>
auto
fixed_string<N, CharT, Traits>::
replace(
size_type pos,
size_type n1,
size_type n2,
CharT c) -> fixed_string<N, CharT, Traits> &
{
if (pos > size())
BOOST_THROW_EXCEPTION(std::out_of_range{
"pos > size()"});
if ((size() - n1 + n2) > max_size())
BOOST_THROW_EXCEPTION(std::length_error{
"replaced string exceeds max_size()"});
Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1);
Traits::assign(&s_[pos], n2, c);
n_ += (n2 - n1);
return *this;
}
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
auto auto