diff options
Diffstat (limited to 'include/ocl/tproc')
| -rw-r--r-- | include/ocl/tproc/detail/config.hpp | 6 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.hpp | 20 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.inl | 27 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.hpp | 65 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.inl | 16 |
5 files changed, 85 insertions, 49 deletions
diff --git a/include/ocl/tproc/detail/config.hpp b/include/ocl/tproc/detail/config.hpp index 89026a2..873cced 100644 --- a/include/ocl/tproc/detail/config.hpp +++ b/include/ocl/tproc/detail/config.hpp @@ -13,5 +13,11 @@ #include <ocl/option.hpp> #include <ocl/smart_ptr.hpp> #include <boost/core/detail/string_view.hpp> +#include <iterator> + +namespace ocl::tproc +{ + +} #endif // ifndef __OCL_TPROC_CONFIG diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp index 6513a01..8d1570d 100644 --- a/include/ocl/tproc/detail/rope_fwd.hpp +++ b/include/ocl/tproc/detail/rope_fwd.hpp @@ -29,7 +29,7 @@ namespace ocl::tproc using const_reference = const CharT&; using pointer = std::allocator_traits<Allocator>::pointer; using const_pointer = std::allocator_traits<Allocator>::pointer; - using iterator_type = basic_rope<CharT, Traits, Allocator>&; + using iterator_type = basic_rope<CharT, Traits, Allocator>*; iterator_type rbegin(); iterator_type rend(); @@ -38,14 +38,20 @@ namespace ocl::tproc iterator_type end(); /// \todo do we need const_iterator_type now? - const iterator_type cbegin() const; - const iterator_type cend() const; + const iterator_type cbegin(); + const iterator_type cend(); /// \brief Extarcts a needle from a position of n length. basic_rope<CharT, Traits, Allocator>& substr(size_type pos, const size_type n = 0); /// \brief Rope's version of the find method. - size_type at(const boost::core::string_view& needle); + size_type at(const boost::core::basic_string_view<CharT>& needle); + + bool starts_with(const basic_rope<CharT>&); + bool ends_with(const basic_rope<CharT>&); + + bool starts_with(const boost::core::basic_string_view<CharT>&); + bool ends_with(const boost::core::basic_string_view<CharT>&); size_type size(); bool empty() const; @@ -60,6 +66,12 @@ namespace ocl::tproc basic_rope& operator=(basic_rope&& rope); basic_rope(basic_rope&& rope); + bool operator!=(const basic_rope& rope); + bool operator==(const basic_rope& rope); + + bool operator!=(const boost::core::basic_string_view<CharT>&); + bool operator==(const boost::core::basic_string_view<CharT>&); + 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 43dfc1b..c171c20 100644 --- a/include/ocl/tproc/detail/rope_fwd.inl +++ b/include/ocl/tproc/detail/rope_fwd.inl @@ -18,8 +18,9 @@ namespace ocl::tproc private: std::allocator_traits<Allocator>::size_type size_; - char_type * head_, *tail_{}; + basic_rope<CharT, Traits, Allocator> * head_, *tail_{}; boost::system::error_code ec_{}; + CharT* blob_{}; public: std::allocator_traits<Allocator>::size_type size() @@ -27,12 +28,12 @@ namespace ocl::tproc return size_; } - CharT* begin() + basic_rope<CharT, Traits, Allocator> * begin() { return head_; } - CharT* end() + basic_rope<CharT, Traits, Allocator> * end() { return tail_; } @@ -63,14 +64,14 @@ namespace ocl::tproc template <class CharT, class Traits, class Allocator> basic_rope<CharT, Traits, Allocator>& - basic_rope<CharT, Traits, Allocator>::operator=(basic_rope&& other) + basic_rope<CharT, Traits, Allocator>::operator=(const basic_rope& other) { impl_ = std::exchange(other.impl_, nullptr); return *this; } template <class CharT, class Traits, class Allocator> - basic_rope<CharT, Traits, Allocator>::basic_rope(basic_rope&& other) + basic_rope<CharT, Traits, Allocator>::basic_rope(const basic_rope& other) { impl_ = std::exchange(other.impl_, nullptr); } @@ -83,13 +84,25 @@ namespace ocl::tproc } template <class CharT, class Traits, class Allocator> - CharT* basic_rope<CharT, Traits, Allocator>::begin() + basic_rope<CharT, Traits, Allocator>::iterator_type basic_rope<CharT, Traits, Allocator>::begin() { return impl_->begin(); } template <class CharT, class Traits, class Allocator> - CharT* basic_rope<CharT, Traits, Allocator>::end() + basic_rope<CharT, Traits, Allocator>::iterator_type basic_rope<CharT, Traits, Allocator>::end() + { + return impl_->end(); + } + + template <class CharT, class Traits, class Allocator> + const basic_rope<CharT, Traits, Allocator>::iterator_type basic_rope<CharT, Traits, Allocator>::cbegin() + { + return impl_->begin(); + } + + template <class CharT, class Traits, class Allocator> + const basic_rope<CharT, Traits, Allocator>::iterator_type basic_rope<CharT, Traits, Allocator>::cend() { return impl_->end(); } diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp index 5842f01..881cd52 100644 --- a/include/ocl/tproc/rope.hpp +++ b/include/ocl/tproc/rope.hpp @@ -7,26 +7,25 @@ #define __OCL_TPROC_ROPE_HPP #include <ocl/tproc/detail/rope_fwd.hpp> -#include <string> namespace ocl::tproc::rope { - /// \brief rbegin exact pred type. + /// \brief reverse exact pred type. + template <typename It> class reverse_pred final { - std::string cond_; + It cond_; public: - reverse_pred(const boost::core::string_view& cond) + reverse_pred(const boost::core::basic_string_view<typename It::value_type>& cond) : cond_(cond) { } - template <typename It> - It operator()(It rbegin, It rend) + It* operator()(It* rbegin, It* rend) { - for (auto rbeg{rbegin}; rbegin != rend; ++rbeg) + for (auto rbeg{rbegin}; rbeg != rend; ++rbeg) { if (*rbeg == cond_) return rbeg; @@ -36,26 +35,26 @@ namespace ocl::tproc::rope } }; + template <typename It> class uppercase_pred final { - std::string cond_; + It cond_; public: - uppercase_pred(const boost::core::string_view& cond) + uppercase_pred(const boost::core::basic_string_view<typename It::value_type>& cond) : cond_(cond) { } - template <typename It> - It operator()(It begin, It end) + It* operator()(It* begin, It* end) { std::transform(cond_.begin(), cond_.end(), - [](std::string::char_type& ch) { + [](std::allocator_traits<It>::value_type& ch) { return std::toupper(ch); }); - for (auto beg{begin}; begin != end; ++beg) + for (auto beg{begin}; beg != end; ++beg) { if (*beg == cond_) return beg; @@ -65,26 +64,26 @@ namespace ocl::tproc::rope } }; + template <typename It> class lowercase_pred final { - std::string cond_; + It cond_; public: - lowercase_pred(const boost::core::string_view& cond) + lowercase_pred(const boost::core::basic_string_view<typename It::value_type>& cond) : cond_(cond) { } - template <typename It> - It operator()(It begin, It end) + It* operator()(It* begin, It* end) { std::transform(cond_.begin(), cond_.end(), - [](std::string::char_type& ch) { + [](std::allocator_traits<ocl::tproc::crope>::value_type& ch) { return std::tolower(ch); }); - for (auto beg{begin}; begin != end; ++beg) + for (auto beg{begin}; beg != end; ++beg) { if (*beg == cond_) return beg; @@ -94,20 +93,20 @@ namespace ocl::tproc::rope } }; + template <typename It> class exact_pred final { - std::string cond_; + It cond_; public: - exact_pred(const boost::core::string_view& cond) + exact_pred(const boost::core::basic_string_view<typename It::value_type>& cond) : cond_(cond) { } - template <typename It> - It operator()(It begin, It end) + It* operator()(It* begin, It* end) { - for (auto beg{begin}; begin != end; ++beg) + for (auto beg{begin}; beg != end; ++beg) { if (*beg == cond_) return beg; @@ -117,19 +116,25 @@ namespace ocl::tproc::rope } }; + template <typename It> class starts_with_pred final { - std::string cond_; + It cond_; public: - starts_with_pred(const boost::core::string_view& cond) + starts_with_pred(const boost::core::basic_string_view<typename It::value_type>& cond) : cond_(cond) { } - template <typename It> - It operator()(It begin, It end) + It* operator()(It* begin, It* end) { + for (auto beg{begin}; beg != end; ++beg) + { + if (beg->starts_with(cond_)) + return beg; + } + return end; } }; @@ -146,10 +151,10 @@ namespace ocl::tproc Pred find_if(It begin, It end, Pred); template <typename It, class Pred> - It::typename size_type erase(It begin, It end, Pred); + Pred::size_type erase(It begin, It end, Pred); template <typename It, class Pred> - It::typename size_type erase_if(It begin, It end, Pred); + Pred::size_type erase_if(It begin, It end, Pred); } // namespace ocl::tproc diff --git a/include/ocl/tproc/rope.inl b/include/ocl/tproc/rope.inl index d53899f..b30b237 100644 --- a/include/ocl/tproc/rope.inl +++ b/include/ocl/tproc/rope.inl @@ -16,7 +16,7 @@ namespace ocl::tproc::rope { if (*it == pred) { - return it; + return *it; } } @@ -28,9 +28,9 @@ namespace ocl::tproc::rope { for (auto it = begin; it != end; ++it) { - if (pred(it, pred)) + if (pred(it)) { - return it; + return *it; } } @@ -38,10 +38,10 @@ namespace ocl::tproc::rope } template <typename It, class Pred> - It::typename size_type erase(It begin, It end, Pred) + typename Pred::size_type erase(It begin, It end, Pred pred) { It original_begin = begin; - size_t count = 0; + typename Pred::size_type count{}; for (auto it = begin; it != end;) { @@ -60,14 +60,14 @@ namespace ocl::tproc::rope } template <typename It, class Pred> - It::typename size_type erase_if(It begin, It end, Pred) + typename It::size_type erase_if(It begin, It end, Pred) { It original_begin = begin; - size_t count = 0; + typename Pred::size_type count{}; for (auto it = begin; it != end;) { - if (pred(it, end) != end) + if (pred(it)) { it = begin.erase(it); ++count; |
