| 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 contains.hpp |
| 9 | * \author Andrey Semashev |
| 10 | * \date 30.03.2008 |
| 11 | * |
| 12 | * This header contains a predicate for checking if the provided string contains a substring. |
| 13 | */ |
| 14 | |
| 15 | #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_CONTAINS_HPP_INCLUDED_ |
| 16 | #define BOOST_LOG_UTILITY_FUNCTIONAL_CONTAINS_HPP_INCLUDED_ |
| 17 | |
| 18 | #include <boost/log/detail/config.hpp> |
| 19 | #include <boost/log/detail/header.hpp> |
| 20 | |
| 21 | #ifdef BOOST_HAS_PRAGMA_ONCE |
| 22 | #pragma once |
| 23 | #endif |
| 24 | |
| 25 | namespace boost { |
| 26 | |
| 27 | BOOST_LOG_OPEN_NAMESPACE |
| 28 | |
| 29 | //! The \c contains functor |
| 30 | struct contains_fun |
| 31 | { |
| 32 | typedef bool result_type; |
| 33 | |
| 34 | template< typename T, typename U > |
| 35 | bool operator() (T const& left, U const& right) const |
| 36 | { |
| 37 | typedef typename T::const_iterator left_iterator; |
| 38 | typedef typename U::const_iterator right_iterator; |
| 39 | |
| 40 | typename U::size_type const right_size = right.size(); |
| 41 | if (left.size() >= right_size) |
| 42 | { |
| 43 | const left_iterator search_end = left.end() - right_size + 1; |
| 44 | const right_iterator right_end = right.end(); |
| 45 | for (left_iterator it = left.begin(); it != search_end; ++it) |
| 46 | { |
| 47 | left_iterator left_it = it; |
| 48 | right_iterator right_it = right.begin(); |
| 49 | for (; right_it != right_end; ++left_it, ++right_it) |
| 50 | { |
| 51 | if (*left_it != *right_it) |
| 52 | break; |
| 53 | } |
| 54 | if (right_it == right_end) |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return false; |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | BOOST_LOG_CLOSE_NAMESPACE // namespace log |
| 64 | |
| 65 | } // namespace boost |
| 66 | |
| 67 | #include <boost/log/detail/footer.hpp> |
| 68 | |
| 69 | #endif // BOOST_LOG_UTILITY_FUNCTIONAL_CONTAINS_HPP_INCLUDED_ |
| 70 |
