diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2010-08-17 20:42:03 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2010-08-17 20:42:03 +0000 |
| commit | 14dcd3d1ff4da48deed3f619dc57f485f9374299 (patch) | |
| tree | 13d402bb5cebdf192207f7fcff070175a502091d /libcxx/include/regex | |
| parent | e2cbaf6ed7712880477888608d7e7eb2b787d949 (diff) | |
| download | bcm5719-llvm-14dcd3d1ff4da48deed3f619dc57f485f9374299.tar.gz bcm5719-llvm-14dcd3d1ff4da48deed3f619dc57f485f9374299.zip | |
[re.tokiter]
llvm-svn: 111278
Diffstat (limited to 'libcxx/include/regex')
| -rw-r--r-- | libcxx/include/regex | 225 |
1 files changed, 213 insertions, 12 deletions
diff --git a/libcxx/include/regex b/libcxx/include/regex index d312468f7f3..dc53498858f 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6038,33 +6038,234 @@ public: typedef const value_type& reference; typedef forward_iterator_tag iterator_category; +private: + typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; + + _Position __position_; + const value_type* __result_; + value_type __suffix_; + ptrdiff_t _N_; + vector<int> __subs_; + +public: regex_token_iterator(); regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, const regex_type& __re, int __submatch = 0, - regex_constants::match_flag_type __m = regex_constants::match_default); + regex_constants::match_flag_type __m = + regex_constants::match_default); regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, const regex_type& __re, const vector<int>& __submatches, - regex_constants::match_flag_type __m = regex_constants::match_default); + regex_constants::match_flag_type __m = + regex_constants::match_default); regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, - const regex_type& __re, initializer_list<int> __submatches, - regex_constants::match_flag_type __m = regex_constants::match_default); + const regex_type& __re, + initializer_list<int> __submatches, + regex_constants::match_flag_type __m = + regex_constants::match_default); template <size_t _N> - regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, - const regex_type& __re, const int (&__submatches)[_N], - regex_constants::match_flag_type __m = regex_constants::match_default); + regex_token_iterator(_BidirectionalIterator __a, + _BidirectionalIterator __b, + const regex_type& __re, + const int (&__submatches)[_N], + regex_constants::match_flag_type __m = + regex_constants::match_default); regex_token_iterator(const regex_token_iterator&); regex_token_iterator& operator=(const regex_token_iterator&); - bool operator==(const regex_token_iterator&) const; - bool operator!=(const regex_token_iterator&) const; + bool operator==(const regex_token_iterator& __x) const; + bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} - const value_type& operator*() const; - const value_type* operator->() const; + const value_type& operator*() const {return *__result_;} + const value_type* operator->() const {return __result_;} regex_token_iterator& operator++(); - regex_token_iterator operator++(int); + regex_token_iterator operator++(int) + { + regex_token_iterator __t(*this); + ++(*this); + return __t; + } + +private: + void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); }; +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator() + : __result_(nullptr), + __suffix_(), + _N_(0) +{ +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +void +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + __init(_BidirectionalIterator __a, _BidirectionalIterator __b) +{ + if (__position_ != _Position()) + { + if (__subs_[_N_] == -1) + __result_ = &__position_->prefix(); + else + __result_ = &(*__position_)[__subs_[_N_]]; + } + else if (__subs_[_N_] == -1) + { + __suffix_.matched = true; + __suffix_.first = __a; + __suffix_.second = __b; + __result_ = &__suffix_; + } + else + __result_ = nullptr; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, int __submatch, + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + _N_(0), + __subs_(1, __submatch) +{ + __init(__a, __b); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, const vector<int>& __submatches, + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + _N_(0), + __subs_(__submatches) +{ + __init(__a, __b); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, + initializer_list<int> __submatches, + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + _N_(0), + __subs_(__submatches) +{ + __init(__a, __b); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +template <size_t _N> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, + const int (&__submatches)[_N], + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + _N_(0), + __subs_(__submatches, __submatches + _N) +{ + __init(__a, __b); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(const regex_token_iterator& __x) + : __position_(__x.__position_), + __result_(__x.__result_), + __suffix_(__x.__suffix_), + _N_(__x._N_), + __subs_(__x.__subs_) +{ + if (__x.__result_ == &__x.__suffix_) + __result_ == &__suffix_; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + operator=(const regex_token_iterator& __x) +{ + if (this != &__x) + { + __position_ = __x.__position_; + if (__x.__result_ == &__x.__suffix_) + __result_ == &__suffix_; + else + __result_ = __x.__result_; + __suffix_ = __x.__suffix_; + _N_ = __x._N_; + __subs_ = __x.__subs_; + } + return *this; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +bool +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + operator==(const regex_token_iterator& __x) const +{ + if (__result_ == nullptr && __x.__result_ == nullptr) + return true; + if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && + __suffix_ == __x.__suffix_) + return true; + if (__result_ == nullptr || __x.__result_ == nullptr) + return false; + if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) + return false; + return __position_ == __x.__position_ && _N_ == __x._N_ && + __subs_ == __x.__subs_; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() +{ + _Position __prev = __position_; + if (__result_ == &__suffix_) + __result_ = nullptr; + else if (_N_ + 1 < __subs_.size()) + { + ++_N_; + if (__subs_[_N_] == -1) + __result_ = &__position_->prefix(); + else + __result_ = &(*__position_)[__subs_[_N_]]; + } + else + { + _N_ = 0; + ++__position_; + if (__position_ != _Position()) + { + if (__subs_[_N_] == -1) + __result_ = &__position_->prefix(); + else + __result_ = &(*__position_)[__subs_[_N_]]; + } + else + { + if (_STD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() + && __prev->suffix().length() != 0) + { + __suffix_.matched = true; + __suffix_.first = __prev->suffix().first; + __suffix_.second = __prev->suffix().second; + __result_ = &__suffix_; + } + else + __result_ = nullptr; + } + } + return *this; +} + typedef regex_token_iterator<const char*> cregex_token_iterator; typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |

