predicate.hpp 2.4 KB

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