| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/CPPAlliance/http_proto | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_MOVE_CHARS_HPP | ||
| 11 | #define BOOST_HTTP_PROTO_DETAIL_MOVE_CHARS_HPP | ||
| 12 | |||
| 13 | #include <boost/core/detail/string_view.hpp> | ||
| 14 | #include <cstring> | ||
| 15 | #include <functional> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace http_proto { | ||
| 19 | namespace detail { | ||
| 20 | |||
| 21 | // Moves characters, and adjusts any passed | ||
| 22 | // views if they point to any moved characters. | ||
| 23 | |||
| 24 | // true if s completely overlapped by buf | ||
| 25 | inline | ||
| 26 | bool | ||
| 27 | 198 | is_overlapping( | |
| 28 | core::string_view buf, | ||
| 29 | core::string_view s) noexcept | ||
| 30 | { | ||
| 31 | 198 | auto const b0 = buf.data(); | |
| 32 | 198 | auto const e0 = b0 + buf.size(); | |
| 33 | 198 | auto const b1 = s.data(); | |
| 34 | 198 | auto const e1 = b1 + s.size(); | |
| 35 | auto const less_equal = | ||
| 36 | std::less_equal<char const*>(); | ||
| 37 |
2/2✓ Branch 1 taken 73 times.
✓ Branch 2 taken 125 times.
|
198 | if(less_equal(e0, b1)) |
| 38 | 73 | return false; | |
| 39 |
2/2✓ Branch 1 taken 119 times.
✓ Branch 2 taken 6 times.
|
125 | if(less_equal(e1, b0)) |
| 40 | 119 | return false; | |
| 41 | // partial overlap is undefined | ||
| 42 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | BOOST_ASSERT(less_equal(e1, e0)); |
| 43 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | BOOST_ASSERT(less_equal(b0, b1)); |
| 44 | 6 | return true; | |
| 45 | } | ||
| 46 | |||
| 47 | inline | ||
| 48 | void | ||
| 49 | 110 | move_chars_impl( | |
| 50 | char*, | ||
| 51 | char const*, | ||
| 52 | core::string_view const&) noexcept | ||
| 53 | { | ||
| 54 | 110 | } | |
| 55 | |||
| 56 | template<class... Sn> | ||
| 57 | void | ||
| 58 | 440 | move_chars_impl( | |
| 59 | char* dest, | ||
| 60 | char const* src, | ||
| 61 | core::string_view const& buf, | ||
| 62 | core::string_view* s, | ||
| 63 | Sn&&... sn) noexcept | ||
| 64 | { | ||
| 65 |
6/6✓ Branch 0 taken 198 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 192 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 214 times.
|
836 | if( s != nullptr && |
| 66 | 396 | is_overlapping(buf, *s)) | |
| 67 | { | ||
| 68 | 12 | *s = { s->data() + (dest - src), s->size() }; | |
| 69 | } | ||
| 70 | 440 | move_chars_impl(dest, src, buf, sn...); | |
| 71 | 440 | } | |
| 72 | |||
| 73 | template<class... Args> | ||
| 74 | void | ||
| 75 | 220 | move_chars( | |
| 76 | char* dest, | ||
| 77 | char const* src, | ||
| 78 | std::size_t n, | ||
| 79 | Args&&... args) noexcept | ||
| 80 | { | ||
| 81 | 220 | move_chars_impl( | |
| 82 | dest, | ||
| 83 | src, | ||
| 84 | 220 | core::string_view(src, n), | |
| 85 | args...); | ||
| 86 | 220 | std::memmove( | |
| 87 | dest, src, n); | ||
| 88 | 220 | } | |
| 89 | |||
| 90 | } // detail | ||
| 91 | } // http_proto | ||
| 92 | } // boost | ||
| 93 | |||
| 94 | #endif | ||
| 95 |