Chris@102: /* Chris@102: * Copyright Andrey Semashev 2007 - 2015. Chris@102: * Distributed under the Boost Software License, Version 1.0. Chris@102: * (See accompanying file LICENSE_1_0.txt or copy at Chris@102: * http://www.boost.org/LICENSE_1_0.txt) Chris@102: */ Chris@102: /*! Chris@102: * \file support/std_regex.hpp Chris@102: * \author Andrey Semashev Chris@102: * \date 19.03.2014 Chris@102: * Chris@102: * This header enables \c std::regex support for Boost.Log. Chris@102: */ Chris@102: Chris@102: #ifndef BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_ Chris@102: #define BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_ Chris@102: Chris@102: #include Chris@102: Chris@102: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@102: #pragma once Chris@102: #endif Chris@102: Chris@102: #if defined(BOOST_NO_CXX11_HDR_REGEX) Chris@102: Chris@102: #if defined(__GNUC__) Chris@102: #pragma message "Boost.Log: This header requires support for std::regex in the standard library." Chris@102: #elif defined(_MSC_VER) Chris@102: #pragma message("Boost.Log: This header requires support for std::regex in the standard library.") Chris@102: #endif Chris@102: Chris@102: #else // defined(BOOST_NO_CXX11_HDR_REGEX) Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: namespace boost { Chris@102: Chris@102: BOOST_LOG_OPEN_NAMESPACE Chris@102: Chris@102: namespace aux { Chris@102: Chris@102: //! This tag type is used if an expression is recognized as \c std::regex Chris@102: struct std_regex_expression_tag; Chris@102: Chris@102: //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits Chris@102: template< typename CharT, typename ReTraitsT > Chris@102: struct matching_expression_kind< std::basic_regex< CharT, ReTraitsT > > Chris@102: { Chris@102: typedef std_regex_expression_tag type; Chris@102: }; Chris@102: Chris@102: //! The matching function implementation Chris@102: template< typename ExpressionT > Chris@102: struct match_traits< ExpressionT, std_regex_expression_tag > Chris@102: { Chris@102: typedef ExpressionT compiled_type; Chris@102: static compiled_type compile(ExpressionT const& expr) { return expr; } Chris@102: Chris@102: template< typename StringT, typename CharT, typename ReTraitsT > Chris@102: 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) Chris@102: { Chris@102: return std::regex_match(str.begin(), str.end(), expr, flags); Chris@102: } Chris@102: Chris@102: template< typename CharT, typename StringTraitsT, typename AllocatorT, typename ReTraitsT > Chris@102: 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) Chris@102: { Chris@102: const CharT* p = str.c_str(); Chris@102: return std::regex_match(p, p + str.size(), expr, flags); Chris@102: } Chris@102: }; Chris@102: Chris@102: } // namespace aux Chris@102: Chris@102: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@102: Chris@102: } // namespace boost Chris@102: Chris@102: #include Chris@102: Chris@102: #endif // defined(BOOST_NO_CXX11_HDR_REGEX) Chris@102: Chris@102: #endif // BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_