• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   support/regex.hpp
9  * \author Andrey Semashev
10  * \date   18.07.2009
11  *
12  * This header enables Boost.Regex support for Boost.Log.
13  */
14 
15 #ifndef BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
16 #define BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
17 
18 #include <string>
19 #include <boost/regex.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/utility/functional/matches.hpp>
22 #include <boost/log/detail/header.hpp>
23 
24 #ifdef BOOST_HAS_PRAGMA_ONCE
25 #pragma once
26 #endif
27 
28 namespace boost {
29 
30 BOOST_LOG_OPEN_NAMESPACE
31 
32 namespace aux {
33 
34 //! This tag type is used if an expression is recognized as a Boost.Regex expression
35 struct boost_regex_expression_tag;
36 
37 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
38 template< typename CharT, typename TraitsT >
39 struct matching_expression_kind< boost::basic_regex< CharT, TraitsT > >
40 {
41     typedef boost_regex_expression_tag type;
42 };
43 
44 //! The matching function implementation
45 template< typename ExpressionT >
46 struct match_traits< ExpressionT, boost_regex_expression_tag >
47 {
48     typedef ExpressionT compiled_type;
compileboost::aux::match_traits49     static compiled_type compile(ExpressionT const& expr) { return expr; }
50 
51     template< typename StringT, typename CharT, typename TraitsT >
matchesboost::aux::match_traits52     static bool matches(StringT const& str, boost::basic_regex< CharT, TraitsT > const& expr, boost::regex_constants::match_flag_type flags = boost::regex_constants::match_default)
53     {
54         return boost::regex_match(str.begin(), str.end(), expr, flags);
55     }
56 
57     template< typename CharT, typename StringTraitsT, typename AllocatorT, typename ReTraitsT >
matchesboost::aux::match_traits58     static bool matches(
59         std::basic_string< CharT, StringTraitsT, AllocatorT > const& str,
60         boost::basic_regex< CharT, ReTraitsT > const& expr,
61         boost::regex_constants::match_flag_type flags = boost::regex_constants::match_default)
62     {
63         const CharT* p = str.c_str();
64         return boost::regex_match(p, p + str.size(), expr, flags);
65     }
66 };
67 
68 } // namespace aux
69 
70 BOOST_LOG_CLOSE_NAMESPACE // namespace log
71 
72 } // namespace boost
73 
74 #include <boost/log/detail/footer.hpp>
75 
76 #endif // BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
77