| 1 | // Boost string_algo library predicate.hpp header file ---------------------------// |
|---|
| 2 | |
|---|
| 3 | // Copyright Pavol Droba 2002-2003. Use, modification and |
|---|
| 4 | // distribution is subject to the Boost Software License, Version |
|---|
| 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 6 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 7 | |
|---|
| 8 | // See http://www.boost.org for updates, documentation, and revision history. |
|---|
| 9 | |
|---|
| 10 | #ifndef BOOST_STRING_PREDICATE_DETAIL_HPP |
|---|
| 11 | #define BOOST_STRING_PREDICATE_DETAIL_HPP |
|---|
| 12 | |
|---|
| 13 | #include <iterator> |
|---|
| 14 | #include <boost/algorithm/string/find.hpp> |
|---|
| 15 | |
|---|
| 16 | namespace boost { |
|---|
| 17 | namespace algorithm { |
|---|
| 18 | namespace detail { |
|---|
| 19 | |
|---|
| 20 | // ends_with predicate implementation ----------------------------------// |
|---|
| 21 | |
|---|
| 22 | template< |
|---|
| 23 | typename ForwardIterator1T, |
|---|
| 24 | typename ForwardIterator2T, |
|---|
| 25 | typename PredicateT> |
|---|
| 26 | inline bool ends_with_iter_select( |
|---|
| 27 | ForwardIterator1T Begin, |
|---|
| 28 | ForwardIterator1T End, |
|---|
| 29 | ForwardIterator2T SubBegin, |
|---|
| 30 | ForwardIterator2T SubEnd, |
|---|
| 31 | PredicateT Comp, |
|---|
| 32 | std::bidirectional_iterator_tag) |
|---|
| 33 | { |
|---|
| 34 | ForwardIterator1T it=End; |
|---|
| 35 | ForwardIterator2T pit=SubEnd; |
|---|
| 36 | for(;it!=Begin && pit!=SubBegin;) |
|---|
| 37 | { |
|---|
| 38 | if( !(Comp(*(--it),*(--pit))) ) |
|---|
| 39 | return false; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | return pit==SubBegin; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | template< |
|---|
| 46 | typename ForwardIterator1T, |
|---|
| 47 | typename ForwardIterator2T, |
|---|
| 48 | typename PredicateT> |
|---|
| 49 | inline bool ends_with_iter_select( |
|---|
| 50 | ForwardIterator1T Begin, |
|---|
| 51 | ForwardIterator1T End, |
|---|
| 52 | ForwardIterator2T SubBegin, |
|---|
| 53 | ForwardIterator2T SubEnd, |
|---|
| 54 | PredicateT Comp, |
|---|
| 55 | std::forward_iterator_tag) |
|---|
| 56 | { |
|---|
| 57 | if ( SubBegin==SubEnd ) |
|---|
| 58 | { |
|---|
| 59 | // empty subsequence check |
|---|
| 60 | return true; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | iterator_range<ForwardIterator1T> Result |
|---|
| 64 | =last_finder( |
|---|
| 65 | make_iterator_range(SubBegin, SubEnd), |
|---|
| 66 | Comp)(Begin, End); |
|---|
| 67 | |
|---|
| 68 | return !Result.empty() && Result.end()==End; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | } // namespace detail |
|---|
| 72 | } // namespace algorithm |
|---|
| 73 | } // namespace boost |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | #endif // BOOST_STRING_PREDICATE_DETAIL_HPP |
|---|