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/std_regex.hpp
0009  * \author Andrey Semashev
0010  * \date   19.03.2014
0011  *
0012  * This header enables \c std::regex support for Boost.Log.
0013  */
0014 
0015 #ifndef BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_
0016 #define BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_
0017 
0018 #include <boost/log/detail/config.hpp>
0019 
0020 #ifdef BOOST_HAS_PRAGMA_ONCE
0021 #pragma once
0022 #endif
0023 
0024 #if defined(BOOST_NO_CXX11_HDR_REGEX)
0025 
0026 #if defined(__GNUC__)
0027 #pragma message "Boost.Log: This header requires support for std::regex in the standard library."
0028 #elif defined(_MSC_VER)
0029 #pragma message("Boost.Log: This header requires support for std::regex in the standard library.")
0030 #endif
0031 
0032 #else // defined(BOOST_NO_CXX11_HDR_REGEX)
0033 
0034 #include <regex>
0035 #include <string>
0036 #include <boost/log/utility/functional/matches.hpp>
0037 #include <boost/log/detail/header.hpp>
0038 
0039 namespace boost {
0040 
0041 BOOST_LOG_OPEN_NAMESPACE
0042 
0043 namespace aux {
0044 
0045 //! This tag type is used if an expression is recognized as \c std::regex
0046 struct std_regex_expression_tag;
0047 
0048 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
0049 template< typename CharT, typename ReTraitsT >
0050 struct matching_expression_kind< std::basic_regex< CharT, ReTraitsT > >
0051 {
0052     typedef std_regex_expression_tag type;
0053 };
0054 
0055 //! The matching function implementation
0056 template< typename ExpressionT >
0057 struct match_traits< ExpressionT, std_regex_expression_tag >
0058 {
0059     typedef ExpressionT compiled_type;
0060     static compiled_type compile(ExpressionT const& expr) { return expr; }
0061 
0062     template< typename StringT, typename CharT, typename ReTraitsT >
0063     static bool matches(StringT const& str, std::basic_regex< CharT, ReTraitsT > const& expr, std::regex_constants::match_flag_type flags = std::regex_constants::match_default)
0064     {
0065         return std::regex_match(str.begin(), str.end(), expr, flags);
0066     }
0067 
0068     template< typename CharT, typename StringTraitsT, typename AllocatorT, typename ReTraitsT >
0069     static bool matches(std::basic_string< CharT, StringTraitsT, AllocatorT > const& str, std::basic_regex< CharT, ReTraitsT > const& expr, std::regex_constants::match_flag_type flags = std::regex_constants::match_default)
0070     {
0071         const CharT* p = str.c_str();
0072         return std::regex_match(p, p + str.size(), expr, flags);
0073     }
0074 };
0075 
0076 } // namespace aux
0077 
0078 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0079 
0080 } // namespace boost
0081 
0082 #include <boost/log/detail/footer.hpp>
0083 
0084 #endif // defined(BOOST_NO_CXX11_HDR_REGEX)
0085 
0086 #endif // BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_