Chris@16
|
1 /*
|
Chris@16
|
2 * Copyright Andrey Semashev 2007 - 2013.
|
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 support/regex.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 18.07.2009
|
Chris@16
|
11 *
|
Chris@16
|
12 * This header enables Boost.Regex support for Boost.Log.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/regex.hpp>
|
Chris@16
|
19 #include <boost/mpl/bool.hpp>
|
Chris@16
|
20 #include <boost/log/detail/config.hpp>
|
Chris@16
|
21 #include <boost/log/utility/functional/matches.hpp>
|
Chris@16
|
22 #include <boost/log/detail/header.hpp>
|
Chris@16
|
23
|
Chris@16
|
24 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
25 #pragma once
|
Chris@16
|
26 #endif
|
Chris@16
|
27
|
Chris@16
|
28 namespace boost {
|
Chris@16
|
29
|
Chris@16
|
30 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
31
|
Chris@16
|
32 namespace aux {
|
Chris@16
|
33
|
Chris@16
|
34 //! The trait verifies if the type can be converted to a Boost.Regex expression
|
Chris@16
|
35 template< typename T >
|
Chris@16
|
36 struct is_regex< T, true >
|
Chris@16
|
37 {
|
Chris@16
|
38 private:
|
Chris@16
|
39 typedef char yes_type;
|
Chris@16
|
40 struct no_type { char dummy[2]; };
|
Chris@16
|
41
|
Chris@16
|
42 template< typename CharT, typename TraitsT >
|
Chris@16
|
43 static yes_type check_regex(basic_regex< CharT, TraitsT > const&);
|
Chris@16
|
44 static no_type check_regex(...);
|
Chris@16
|
45 static T& get_T();
|
Chris@16
|
46
|
Chris@16
|
47 public:
|
Chris@16
|
48 enum { value = sizeof(check_regex(get_T())) == sizeof(yes_type) };
|
Chris@16
|
49 typedef mpl::bool_< value > type;
|
Chris@16
|
50 };
|
Chris@16
|
51
|
Chris@16
|
52 //! The regex matching functor implementation
|
Chris@16
|
53 template< >
|
Chris@16
|
54 struct matches_fun_impl< boost_regex_expression_tag >
|
Chris@16
|
55 {
|
Chris@16
|
56 template< typename StringT, typename CharT, typename TraitsT >
|
Chris@16
|
57 static bool matches(
|
Chris@16
|
58 StringT const& str,
|
Chris@16
|
59 basic_regex< CharT, TraitsT > const& expr,
|
Chris@16
|
60 match_flag_type flags = match_default)
|
Chris@16
|
61 {
|
Chris@16
|
62 return boost::regex_match(str.begin(), str.end(), expr, flags);
|
Chris@16
|
63 }
|
Chris@16
|
64 };
|
Chris@16
|
65
|
Chris@16
|
66 } // namespace aux
|
Chris@16
|
67
|
Chris@16
|
68 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
69
|
Chris@16
|
70 } // namespace boost
|
Chris@16
|
71
|
Chris@16
|
72 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
73
|
Chris@16
|
74 #endif // BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
|