src/buffers/buffer_pair.cpp

100.0% Lines (44/44) 100.0% Functions (2/2)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2023 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/capy
8 //
9
10 #include <boost/capy/buffers/buffer_pair.hpp>
11 #include <boost/capy/buffers/slice.hpp>
12
13 namespace boost {
14 namespace capy {
15
16 void
17 1040x tag_invoke(
18 slice_tag const&,
19 const_buffer_pair& bs,
20 slice_how how,
21 std::size_t n) noexcept
22 {
23 1040x switch(how)
24 {
25 512x case slice_how::remove_prefix:
26 {
27 512x auto p = &bs[0];
28 512x if(n < p->size())
29 {
30 225x remove_prefix(*p, n);
31 225x return;
32 }
33 287x n -= p->size();
34 287x *p = bs[1];
35 287x bs[1] = {};
36 287x remove_prefix(*p, n);
37 287x return;
38 }
39
40 528x case slice_how::keep_prefix:
41 {
42 528x auto p = &bs[0];
43 528x if(n <= p->size())
44 {
45 287x keep_prefix(*p, n);
46 287x bs[1] = {};
47 287x return;
48 }
49 241x n -= p->size();
50 241x ++p;
51 241x keep_prefix(*p, n);
52 241x return;
53 }
54 }
55 }
56
57 void
58 1040x tag_invoke(
59 slice_tag const&,
60 mutable_buffer_pair& bs,
61 slice_how how,
62 std::size_t n) noexcept
63 {
64 1040x switch(how)
65 {
66 512x case slice_how::remove_prefix:
67 {
68 512x auto p = &bs[0];
69 512x if(n < p->size())
70 {
71 225x remove_prefix(*p, n);
72 225x return;
73 }
74 287x n -= p->size();
75 287x *p = bs[1];
76 287x bs[1] = {};
77 287x remove_prefix(*p, n);
78 287x return;
79 }
80
81 528x case slice_how::keep_prefix:
82 {
83 528x auto p = &bs[0];
84 528x if(n <= p->size())
85 {
86 287x keep_prefix(*p, n);
87 287x bs[1] = {};
88 287x return;
89 }
90 241x n -= p->size();
91 241x ++p;
92 241x keep_prefix(*p, n);
93 241x return;
94 }
95 }
96 }
97
98 } // capy
99 } // boost
100