123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #ifndef BOOST_URL_DETAIL_MOVE_CHARS_HPP
- #define BOOST_URL_DETAIL_MOVE_CHARS_HPP
- #include <boost/core/detail/string_view.hpp>
- #include <boost/assert.hpp>
- #include <cstring>
- #include <functional>
- namespace boost {
- namespace urls {
- namespace detail {
- inline
- bool
- is_overlapping(
- core::string_view buf,
- core::string_view s) noexcept
- {
- auto const b0 = buf.data();
- auto const e0 = b0 + buf.size();
- auto const b1 = s.data();
- auto const e1 = b1 + s.size();
- auto const less_equal =
- std::less_equal<char const*>();
- if(less_equal(e0, b1))
- return false;
- if(less_equal(e1, b0))
- return false;
-
- BOOST_ASSERT(less_equal(e1, e0));
- BOOST_ASSERT(less_equal(b0, b1));
- return true;
- }
- inline
- void
- move_chars_impl(
- std::ptrdiff_t,
- core::string_view const&) noexcept
- {
- }
- template<class... Sn>
- void
- move_chars_impl(
- std::ptrdiff_t d,
- core::string_view const& buf,
- core::string_view& s,
- Sn&... sn) noexcept
- {
- if(is_overlapping(buf, s))
- s = {s.data() + d, s.size()};
- move_chars_impl(d, buf, sn...);
- }
- template<class... Args>
- void
- move_chars(
- char* dest,
- char const* src,
- std::size_t n,
- Args&... args) noexcept
- {
- core::string_view buf(src, n);
- move_chars_impl(
- dest - src,
- core::string_view(src, n),
- args...);
- std::memmove(
- dest, src, n);
- }
- }
- }
- }
- #endif
|