Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:45:08

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   support/regex.hpp
0009  * \author Andrey Semashev
0010  * \date   18.07.2009
0011  *
0012  * This header enables Boost.Regex support for Boost.Log.
0013  */
0014 
0015 #ifndef BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
0016 #define BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
0017 
0018 #include <string>
0019 #include <boost/regex.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/utility/functional/matches.hpp>
0022 #include <boost/log/detail/header.hpp>
0023 
0024 #ifdef BOOST_HAS_PRAGMA_ONCE
0025 #pragma once
0026 #endif
0027 
0028 namespace boost {
0029 
0030 BOOST_LOG_OPEN_NAMESPACE
0031 
0032 namespace aux {
0033 
0034 //! This tag type is used if an expression is recognized as a Boost.Regex expression
0035 struct boost_regex_expression_tag;
0036 
0037 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
0038 template< typename CharT, typename TraitsT >
0039 struct matching_expression_kind< boost::basic_regex< CharT, TraitsT > >
0040 {
0041     typedef boost_regex_expression_tag type;
0042 };
0043 
0044 //! The matching function implementation
0045 template< typename ExpressionT >
0046 struct match_traits< ExpressionT, boost_regex_expression_tag >
0047 {
0048     typedef ExpressionT compiled_type;
0049     static compiled_type compile(ExpressionT const& expr) { return expr; }
0050 
0051     template< typename StringT, typename CharT, typename TraitsT >
0052     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)
0053     {
0054         return boost::regex_match(str.begin(), str.end(), expr, flags);
0055     }
0056 
0057     template< typename CharT, typename StringTraitsT, typename AllocatorT, typename ReTraitsT >
0058     static bool matches(
0059         std::basic_string< CharT, StringTraitsT, AllocatorT > const& str,
0060         boost::basic_regex< CharT, ReTraitsT > const& expr,
0061         boost::regex_constants::match_flag_type flags = boost::regex_constants::match_default)
0062     {
0063         const CharT* p = str.c_str();
0064         return boost::regex_match(p, p + str.size(), expr, flags);
0065     }
0066 };
0067 
0068 } // namespace aux
0069 
0070 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0071 
0072 } // namespace boost
0073 
0074 #include <boost/log/detail/footer.hpp>
0075 
0076 #endif // BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_