Chris@102
|
1 /*
|
Chris@102
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@102
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@102
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
6 */
|
Chris@102
|
7 /*!
|
Chris@102
|
8 * \file support/std_regex.hpp
|
Chris@102
|
9 * \author Andrey Semashev
|
Chris@102
|
10 * \date 19.03.2014
|
Chris@102
|
11 *
|
Chris@102
|
12 * This header enables \c std::regex support for Boost.Log.
|
Chris@102
|
13 */
|
Chris@102
|
14
|
Chris@102
|
15 #ifndef BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_
|
Chris@102
|
16 #define BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_
|
Chris@102
|
17
|
Chris@102
|
18 #include <boost/log/detail/config.hpp>
|
Chris@102
|
19
|
Chris@102
|
20 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@102
|
21 #pragma once
|
Chris@102
|
22 #endif
|
Chris@102
|
23
|
Chris@102
|
24 #if defined(BOOST_NO_CXX11_HDR_REGEX)
|
Chris@102
|
25
|
Chris@102
|
26 #if defined(__GNUC__)
|
Chris@102
|
27 #pragma message "Boost.Log: This header requires support for std::regex in the standard library."
|
Chris@102
|
28 #elif defined(_MSC_VER)
|
Chris@102
|
29 #pragma message("Boost.Log: This header requires support for std::regex in the standard library.")
|
Chris@102
|
30 #endif
|
Chris@102
|
31
|
Chris@102
|
32 #else // defined(BOOST_NO_CXX11_HDR_REGEX)
|
Chris@102
|
33
|
Chris@102
|
34 #include <regex>
|
Chris@102
|
35 #include <string>
|
Chris@102
|
36 #include <boost/log/utility/functional/matches.hpp>
|
Chris@102
|
37 #include <boost/log/detail/header.hpp>
|
Chris@102
|
38
|
Chris@102
|
39 namespace boost {
|
Chris@102
|
40
|
Chris@102
|
41 BOOST_LOG_OPEN_NAMESPACE
|
Chris@102
|
42
|
Chris@102
|
43 namespace aux {
|
Chris@102
|
44
|
Chris@102
|
45 //! This tag type is used if an expression is recognized as \c std::regex
|
Chris@102
|
46 struct std_regex_expression_tag;
|
Chris@102
|
47
|
Chris@102
|
48 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
|
Chris@102
|
49 template< typename CharT, typename ReTraitsT >
|
Chris@102
|
50 struct matching_expression_kind< std::basic_regex< CharT, ReTraitsT > >
|
Chris@102
|
51 {
|
Chris@102
|
52 typedef std_regex_expression_tag type;
|
Chris@102
|
53 };
|
Chris@102
|
54
|
Chris@102
|
55 //! The matching function implementation
|
Chris@102
|
56 template< typename ExpressionT >
|
Chris@102
|
57 struct match_traits< ExpressionT, std_regex_expression_tag >
|
Chris@102
|
58 {
|
Chris@102
|
59 typedef ExpressionT compiled_type;
|
Chris@102
|
60 static compiled_type compile(ExpressionT const& expr) { return expr; }
|
Chris@102
|
61
|
Chris@102
|
62 template< typename StringT, typename CharT, typename ReTraitsT >
|
Chris@102
|
63 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
|
64 {
|
Chris@102
|
65 return std::regex_match(str.begin(), str.end(), expr, flags);
|
Chris@102
|
66 }
|
Chris@102
|
67
|
Chris@102
|
68 template< typename CharT, typename StringTraitsT, typename AllocatorT, typename ReTraitsT >
|
Chris@102
|
69 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
|
70 {
|
Chris@102
|
71 const CharT* p = str.c_str();
|
Chris@102
|
72 return std::regex_match(p, p + str.size(), expr, flags);
|
Chris@102
|
73 }
|
Chris@102
|
74 };
|
Chris@102
|
75
|
Chris@102
|
76 } // namespace aux
|
Chris@102
|
77
|
Chris@102
|
78 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@102
|
79
|
Chris@102
|
80 } // namespace boost
|
Chris@102
|
81
|
Chris@102
|
82 #include <boost/log/detail/footer.hpp>
|
Chris@102
|
83
|
Chris@102
|
84 #endif // defined(BOOST_NO_CXX11_HDR_REGEX)
|
Chris@102
|
85
|
Chris@102
|
86 #endif // BOOST_LOG_SUPPORT_STD_REGEX_HPP_INCLUDED_
|