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