2 * Copyright Andrey Semashev 2007 - 2014.
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)
8 * \file support/xpressive.hpp
9 * \author Andrey Semashev
12 * This header enables Boost.Xpressive support for Boost.Log.
15 #ifndef BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_
16 #define BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_
19 #include <boost/xpressive/basic_regex.hpp>
20 #include <boost/xpressive/regex_constants.hpp>
21 #include <boost/xpressive/regex_algorithms.hpp>
22 #include <boost/log/detail/config.hpp>
23 #include <boost/log/utility/functional/matches.hpp>
24 #include <boost/log/detail/header.hpp>
26 #ifdef BOOST_HAS_PRAGMA_ONCE
32 BOOST_LOG_OPEN_NAMESPACE
36 //! This tag type is used if an expression is recognized as a Boost.Xpressive expression
37 struct boost_xpressive_expression_tag;
39 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
40 template< typename T >
41 struct matching_expression_kind< xpressive::basic_regex< T > >
43 typedef boost_xpressive_expression_tag type;
46 //! The matching function implementation
47 template< typename ExpressionT >
48 struct match_traits< ExpressionT, boost_xpressive_expression_tag >
50 typedef ExpressionT compiled_type;
51 static compiled_type compile(ExpressionT const& expr) { return expr; }
53 template< typename StringT, typename T >
54 static bool matches(StringT const& str, xpressive::basic_regex< T > const& expr, xpressive::regex_constants::match_flag_type flags = xpressive::regex_constants::match_default)
56 return xpressive::regex_match(str, expr, flags);
59 template< typename CharT, typename TraitsT, typename AllocatorT >
60 static bool matches(std::basic_string< CharT, TraitsT, AllocatorT > const& str, xpressive::basic_regex< const CharT* > const& expr, xpressive::regex_constants::match_flag_type flags = xpressive::regex_constants::match_default)
62 const CharT* p = str.c_str();
63 return xpressive::regex_match(p, p + str.size(), expr, flags);
69 BOOST_LOG_CLOSE_NAMESPACE // namespace log
73 #include <boost/log/detail/footer.hpp>
75 #endif // BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_