diff options
| -rw-r--r-- | include/ocl/tproc.hpp | 2 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.hpp | 17 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.inl | 9 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.hpp | 65 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.inl | 110 |
5 files changed, 129 insertions, 74 deletions
diff --git a/include/ocl/tproc.hpp b/include/ocl/tproc.hpp index b4c4778..c2f9d65 100644 --- a/include/ocl/tproc.hpp +++ b/include/ocl/tproc.hpp @@ -8,6 +8,6 @@ #include <ocl/tproc/detail/config.hpp> #include <ocl/tproc/rope.hpp> -//#include <ocl/tproc/regex.hpp> +// #include <ocl/tproc/regex.hpp> #endif // __OCL_TPROC_HPP diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp index a172f90..5362f9b 100644 --- a/include/ocl/tproc/detail/rope_fwd.hpp +++ b/include/ocl/tproc/detail/rope_fwd.hpp @@ -29,12 +29,17 @@ namespace ocl::tproc using const_reference = const CharT&; using pointer = std::allocator_traits<Allocator>::pointer; using const_pointer = std::allocator_traits<Allocator>::pointer; - - basic_rope<CharT, Traits, Allocator>& begin(); - basic_rope<CharT, Traits, Allocator>& end(); - - const basic_rope<CharT, Traits, Allocator>& cbegin() const; - const basic_rope<CharT, Traits, Allocator>& cend() const; + using iterator_type = basic_rope<CharT, Traits, Allocator>&; + + iterator_type rbegin(); + iterator_type rend(); + + iterator_type begin(); + iterator_type end(); + + /// \todo do we need const_iterator_type now? + const iterator_type cbegin() const; + const iterator_type cend() const; /// \brief Extarcts a needle from a position of n length. basic_rope<CharT, Traits, Allocator>& substr(size_type pos, const size_type n = 0); diff --git a/include/ocl/tproc/detail/rope_fwd.inl b/include/ocl/tproc/detail/rope_fwd.inl index e5d959e..43dfc1b 100644 --- a/include/ocl/tproc/detail/rope_fwd.inl +++ b/include/ocl/tproc/detail/rope_fwd.inl @@ -6,15 +6,20 @@ #ifndef OCL_TPROC_ROPE_FWD_INL #define OCL_TPROC_ROPE_FWD_INL +#include <boost/system/error_code.hpp> + namespace ocl::tproc { template <class CharT, class Traits, class Allocator> struct basic_rope<CharT, Traits, Allocator>::tree_impl { + using char_type = CharT; + private: std::allocator_traits<Allocator>::size_type size_; - CharT *head_, *tail_{}; + char_type * head_, *tail_{}; + boost::system::error_code ec_{}; public: std::allocator_traits<Allocator>::size_type size() @@ -57,7 +62,7 @@ namespace ocl::tproc } template <class CharT, class Traits, class Allocator> - basic_rope<CharT, Traits, Allocator>& + basic_rope<CharT, Traits, Allocator>& basic_rope<CharT, Traits, Allocator>::operator=(basic_rope&& other) { impl_ = std::exchange(other.impl_, nullptr); diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp index 9d9356a..9ad5e93 100644 --- a/include/ocl/tproc/rope.hpp +++ b/include/ocl/tproc/rope.hpp @@ -12,7 +12,8 @@ namespace ocl::tproc::rope { - class reverse_pred + /// \brief rbegin exact pred type. + class reverse_pred final { std::string cond_; @@ -23,10 +24,19 @@ namespace ocl::tproc::rope } template <typename It> - It operator()(It begin, It end); + It operator()(It rbegin, It rend) + { + for (auto rbeg{rbegin}; rbegin != rend; ++rbeg) + { + if (*rbeg == cond_) + return rbeg; + } + + return rend; + } }; - class uppercase_pred + class uppercase_pred final { std::string cond_; @@ -37,10 +47,23 @@ namespace ocl::tproc::rope } template <typename It> - It operator()(It begin, It end); + It operator()(It begin, It end) + { + auto cmp = std::transform(cond_.begin(), cond_.end(), [](std::string::char_type& ch) { + return std::toupper(ch); + }); + + for (auto beg{begin}; begin != end; ++beg) + { + if (*beg == cond_) + return beg; + } + + return end; + } }; - class lowercase_pred + class lowercase_pred final { std::string cond_; @@ -51,10 +74,23 @@ namespace ocl::tproc::rope } template <typename It> - It operator()(It begin, It end); + It operator()(It begin, It end) + { + auto cmp = std::transform(cond_.begin(), cond_.end(), [](std::string::char_type& ch) { + return std::tolower(ch); + }); + + for (auto beg{begin}; begin != end; ++beg) + { + if (*beg == cond_) + return beg; + } + + return end; + } }; - class exact_pred + class exact_pred final { std::string cond_; @@ -65,10 +101,19 @@ namespace ocl::tproc::rope } template <typename It> - It operator()(It begin, It end); + It operator()(It begin, It end) + { + for (auto beg{begin}; begin != end; ++beg) + { + if (*beg == cond_) + return beg; + } + + return end; + } }; - class starts_with_pred + class starts_with_pred final { std::string cond_; @@ -79,7 +124,7 @@ namespace ocl::tproc::rope } template <typename It> - It operator()(It begin, It end); + It operator()(It begin, It end) { return end; } }; } // namespace ocl::tproc::rope diff --git a/include/ocl/tproc/rope.inl b/include/ocl/tproc/rope.inl index fe4218e..4158e16 100644 --- a/include/ocl/tproc/rope.inl +++ b/include/ocl/tproc/rope.inl @@ -8,78 +8,78 @@ namespace ocl::tproc::rope { - + template <typename It, class Pred> It find(It begin, It end, Pred pred) - { - for (auto it = begin; it != end; ++it) - { - if (*it == pred) - { - return it; - } - } + { + for (auto it = begin; it != end; ++it) + { + if (*it == pred) + { + return it; + } + } - return end; - } + return end; + } template <typename It, class Pred> It find_if(It begin, It end, Pred pred) - { - for (auto it = begin; it != end; ++it) - { - if (pred(it, pred)) - { - return it; - } - } + { + for (auto it = begin; it != end; ++it) + { + if (pred(it, pred)) + { + return it; + } + } - return end; - } + return end; + } template <typename It, class Pred> It::typename size_type erase(It begin, It end, Pred) - { - It original_begin = begin; - size_t count = 0; + { + It original_begin = begin; + size_t count = 0; - for (auto it = begin; it != end; ) - { - if (*it == pred) - { - it = begin.erase(it); - ++count; - } - else - { - ++it; - } - } + for (auto it = begin; it != end;) + { + if (*it == pred) + { + it = begin.erase(it); + ++count; + } + else + { + ++it; + } + } - return count; - } + return count; + } template <typename It, class Pred> It::typename size_type erase_if(It begin, It end, Pred) - { - It original_begin = begin; - size_t count = 0; + { + It original_begin = begin; + size_t count = 0; - for (auto it = begin; it != end; ) - { - if (pred(it, end) != end) - { - it = begin.erase(it); - ++count; - } - else - { - ++it; - } - } + for (auto it = begin; it != end;) + { + if (pred(it, end) != end) + { + it = begin.erase(it); + ++count; + } + else + { + ++it; + } + } - return count; - } + return count; + } } // namespace ocl::tproc::rope |
