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