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)
8 * \file support/regex.hpp
9 * \author Andrey Semashev
12 * This header enables Boost.Regex support for Boost.Log.
15 #ifndef BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
16 #define BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
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>
24 #ifdef BOOST_HAS_PRAGMA_ONCE
30 BOOST_LOG_OPEN_NAMESPACE
34 //! This tag type is used if an expression is recognized as a Boost.Regex expression
35 struct boost_regex_expression_tag;
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 > >
41 typedef boost_regex_expression_tag type;
44 //! The matching function implementation
45 template< typename ExpressionT >
46 struct match_traits< ExpressionT, boost_regex_expression_tag >
48 typedef ExpressionT compiled_type;
49 static compiled_type compile(ExpressionT const& expr) { return expr; }
51 template< typename StringT, typename CharT, typename TraitsT >
52 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)
54 return boost::regex_match(str.begin(), str.end(), expr, flags);
57 template< typename CharT, typename StringTraitsT, typename AllocatorT, typename ReTraitsT >
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)
63 const CharT* p = str.c_str();
64 return boost::regex_match(p, p + str.size(), expr, flags);
70 BOOST_LOG_CLOSE_NAMESPACE // namespace log
74 #include <boost/log/detail/footer.hpp>
76 #endif // BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_