ends_with.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file ends_with.hpp
  9. * \author Andrey Semashev
  10. * \date 30.03.2008
  11. *
  12. * This header contains a predicate for checking if the provided string ends with a substring.
  13. */
  14. #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_ENDS_WITH_HPP_INCLUDED_
  15. #define BOOST_LOG_UTILITY_FUNCTIONAL_ENDS_WITH_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #include <boost/log/detail/header.hpp>
  18. #ifdef BOOST_HAS_PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. namespace boost {
  22. BOOST_LOG_OPEN_NAMESPACE
  23. //! The \c ends_with functor
  24. struct ends_with_fun
  25. {
  26. typedef bool result_type;
  27. template< typename T, typename U >
  28. bool operator() (T const& left, U const& right) const
  29. {
  30. typedef typename T::const_reverse_iterator left_iterator;
  31. typedef typename U::const_reverse_iterator right_iterator;
  32. left_iterator left_it = left.rbegin(), left_end = left.rend();
  33. right_iterator right_it = right.rbegin(), right_end = right.rend();
  34. for (; left_it != left_end && right_it != right_end; ++left_it, ++right_it)
  35. {
  36. if (*left_it != *right_it)
  37. break;
  38. }
  39. return right_it == right_end;
  40. }
  41. };
  42. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  43. } // namespace boost
  44. #include <boost/log/detail/footer.hpp>
  45. #endif // BOOST_LOG_UTILITY_FUNCTIONAL_ENDS_WITH_HPP_INCLUDED_