diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.hpp | 4 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.inl | 27 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.hpp | 24 |
3 files changed, 49 insertions, 6 deletions
diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp index 0ce0457..7541795 100644 --- a/include/ocl/tproc/detail/rope_fwd.hpp +++ b/include/ocl/tproc/detail/rope_fwd.hpp @@ -28,7 +28,7 @@ namespace ocl::tproc using reference = CharT&; using const_reference = const CharT&; using pointer = std::allocator_traits<Allocator>::pointer; - using const_pointer = std::allocator_traits<Allocator>::pointer; + using const_pointer = const std::allocator_traits<Allocator>::pointer; using iterator_type = basic_rope<CharT, Traits, Allocator>*; iterator_type rbegin(); @@ -75,6 +75,8 @@ namespace ocl::tproc bool operator!=(const boost::core::basic_string_view<CharT>&); bool operator==(const boost::core::basic_string_view<CharT>&); + iterator_type concat(iterator_type right); + public: static constexpr size_type npos = (size_type)(-1); diff --git a/include/ocl/tproc/detail/rope_fwd.inl b/include/ocl/tproc/detail/rope_fwd.inl index 81a7f5c..01e5bbe 100644 --- a/include/ocl/tproc/detail/rope_fwd.inl +++ b/include/ocl/tproc/detail/rope_fwd.inl @@ -60,11 +60,11 @@ namespace ocl::tproc { std::allocator_traits<Allocator>::deallocate(alloc_, blob_, capacity_); } - + delete left_; delete right_; - left_ = nullptr; + left_ = nullptr; right_ = nullptr; } @@ -91,6 +91,7 @@ namespace ocl::tproc { throw std::out_of_range("rope index out of range"); } + return blob_[pos]; } @@ -109,6 +110,7 @@ namespace ocl::tproc } } + public: static rope_ptr concat(rope_ptr left, rope_ptr right, Allocator alloc = Allocator()) { if (!left) @@ -116,8 +118,14 @@ namespace ocl::tproc if (!right) return left; - auto* new_rope = new basic_rope<CharT, Traits, Allocator>(); - new_rope->impl_ = new tree_impl(left, right, alloc); + auto res = std::basic_string<CharT>(left->data().data(), left->data().size()); + res += std::basic_string<CharT>(right->data().data(), right->data().size()); + + auto* new_rope = new basic_rope<CharT, Traits, Allocator>(res); + + new_rope->impl_->left_ = left; + new_rope->impl_->right_ = right; + return new_rope; } @@ -401,13 +409,14 @@ namespace ocl::tproc return npos; size_type rope_size = impl_->size(); + if (needle.size() > rope_size) return npos; - // Brute force search for (size_type i = 0; i <= rope_size - needle.size(); ++i) { bool match = true; + for (size_type j = 0; j < needle.size(); ++j) { if (impl_->at(i + j) != needle[j]) @@ -416,9 +425,11 @@ namespace ocl::tproc break; } } + if (match) return i; } + return npos; } @@ -526,6 +537,12 @@ namespace ocl::tproc return !(*this == str); } + template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>* basic_rope<CharT, Traits, Allocator>::concat(basic_rope<CharT, Traits, Allocator>* right) + { + return impl_->concat(this, right); + } + } // namespace ocl::tproc #endif
\ No newline at end of file diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp index 26729b0..21277f2 100644 --- a/include/ocl/tproc/rope.hpp +++ b/include/ocl/tproc/rope.hpp @@ -35,6 +35,30 @@ namespace ocl::tproc::rope } }; + /// \brief ends with pred type. + template <typename It> + class ends_with_pred final + { + It cond_; + + public: + ends_with_pred(const boost::core::basic_string_view<typename It::value_type>& cond) + : cond_(cond) + { + } + + It* operator()(It* begin, It* end) + { + for (auto beg{begin}; beg != end; ++beg) + { + if (beg->ends_with(cond_.data())) + return beg; + } + + return end; + } + }; + template <typename It> class uppercase_pred final { |
