Open C++ Libraries.org develop
Loading...
Searching...
No Matches
rope.hpp
1// SPDX-License-Identifier: BSL-1.0
2// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org)
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5// Official repository: https://github.com/open-cpp-libraries/tproc
6
7#ifndef OCL_TPROC_ROPE_HPP
8#define OCL_TPROC_ROPE_HPP
9
11
12namespace ocl::tproc::rope
13{
14
16 template <typename It>
17 class reverse_pred final
18 {
19 It cond_;
20
21 public:
22 reverse_pred(const boost::core::basic_string_view<typename It::value_type>& cond)
23 : cond_(cond)
24 {
25 }
26
27 using iterator_ptr = It*;
28
29 iterator_ptr operator()(iterator_ptr rbegin, iterator_ptr rend)
30 {
31 for (auto rbeg{rbegin}; rbeg != rend; ++rbeg)
32 {
33 if (*rbeg == cond_)
34 return rbeg;
35 }
36
37 return rend;
38 }
39 };
40
42 template <typename It>
43 class ends_with_pred final
44 {
45 It cond_;
46
47 public:
48 ends_with_pred(const boost::core::basic_string_view<typename It::value_type>& cond)
49 : cond_(cond)
50 {
51 }
52
53 using iterator_ptr = It*;
54
55 iterator_ptr operator()(iterator_ptr begin, iterator_ptr end)
56 {
57 for (auto beg{begin}; beg != end; ++beg)
58 {
59 if (beg->ends_with(cond_.to_string()))
60 return beg;
61 }
62
63 return end;
64 }
65 };
66
67 template <typename It>
68 class uppercase_pred final
69 {
70 It cond_;
71
72 public:
73 uppercase_pred(const boost::core::basic_string_view<typename It::value_type>& cond)
74 : cond_(cond)
75 {
76 }
77
78 using iterator_ptr = It*;
79
80 iterator_ptr operator()(iterator_ptr begin, iterator_ptr end)
81 {
82 std::transform(cond_.begin(),
83 cond_.end(),
84 [](std::allocator_traits<It>::value_type& ch) {
85 return std::toupper(ch);
86 });
87
88 for (auto beg{begin}; beg != end; ++beg)
89 {
90 if (*beg == cond_)
91 return beg;
92 }
93
94 return end;
95 }
96 };
97
98 template <typename It>
99 class lowercase_pred final
100 {
101 It cond_;
102
103 public:
104 lowercase_pred(const boost::core::basic_string_view<typename It::value_type>& cond)
105 : cond_(cond)
106 {
107 }
108
109 using iterator_ptr = It*;
110
111 iterator_ptr operator()(iterator_ptr begin, iterator_ptr end)
112 {
113 std::transform(cond_.begin(),
114 cond_.end(),
115 [](std::allocator_traits<It>::value_type& ch) {
116 return std::tolower(ch);
117 });
118
119 for (auto beg{begin}; beg != end; ++beg)
120 {
121 if (*beg == cond_)
122 return beg;
123 }
124
125 return end;
126 }
127 };
128
129 template <typename It>
130 class exact_pred final
131 {
132 It cond_;
133
134 public:
135 exact_pred(const boost::core::basic_string_view<typename It::value_type>& cond)
136 : cond_(cond)
137 {
138 }
139
140 using iterator_ptr = It*;
141
142 iterator_ptr operator()(iterator_ptr begin, iterator_ptr end)
143 {
144 for (auto beg{begin}; beg != end; ++beg)
145 {
146 if (*beg == cond_)
147 return beg;
148 }
149
150 return end;
151 }
152 };
153
154 template <typename It>
156 {
157 It cond_;
158
159 public:
160 starts_with_pred(const boost::core::basic_string_view<typename It::value_type>& cond)
161 : cond_(cond)
162 {
163 }
164
165 using iterator_ptr = It*;
166
167 iterator_ptr operator()(iterator_ptr begin, iterator_ptr end)
168 {
169 for (auto beg{begin}; beg != end; ++beg)
170 {
171 if (beg->starts_with(cond_))
172 return beg;
173 }
174
175 return end;
176 }
177 };
178
179} // namespace ocl::tproc::rope
180
181namespace ocl::tproc
182{
183
184 template <typename It, class Pred>
185 Pred find(It begin, It end, Pred);
186
187 template <typename It, class Pred>
188 Pred find_if(It begin, It end, Pred);
189
190 template <typename It, class Pred>
191 Pred::size_type erase(It begin, It end, Pred);
192
193 template <typename It, class Pred>
194 Pred::size_type erase_if(It begin, It end, Pred);
195
196} // namespace ocl::tproc
197
198inline std::ostream& operator<<(std::ostream& os, ocl::tproc::crope& r)
199{
200 os << r.to_string();
201 return os;
202}
203
204inline std::wostream& operator<<(std::wostream& os, ocl::tproc::wrope& r)
205{
206 os << r.to_string();
207 return os;
208}
209
210inline std::ostream& operator<<(std::ostream& os, const ocl::tproc::crope& r)
211{
212 os << r.to_string();
213 return os;
214}
215
216inline std::wostream& operator<<(std::wostream& os, const ocl::tproc::wrope& r)
217{
218 os << r.to_string();
219 return os;
220}
221
222#include "rope.inl"
223
224#endif // OCL_TPROC_ROPE_HPP
This class implements a rope type for any CharT type.
Definition rope_fwd.hpp:23
ends with pred type.
Definition rope.hpp:44
Definition rope.hpp:131
Definition rope.hpp:100
reverse exact pred type.
Definition rope.hpp:18
Definition rope.hpp:156
Definition rope.hpp:69
AMLALE: SourcePair desrves documentation by themselves.
Definition bfs.hpp:13
Basic forward definitions of the rope type.