Chris@16: /* Chris@16: * Copyright Andrey Semashev 2007 - 2013. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file matches.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 30.03.2008 Chris@16: * Chris@16: * This header contains a predicate for checking if the provided string matches a regular expression. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_MATCHES_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_UTILITY_FUNCTIONAL_MATCHES_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: //! This tag type is used if an expression is not supported for matching against strings Chris@16: struct unsupported_match_expression_tag; Chris@16: //! This tag type is used if an expression is recognized as a Boost.Regex expression Chris@16: struct boost_regex_expression_tag; Chris@16: //! This tag type is used if an expression is recognized as a Boost.Xpressive expression Chris@16: struct boost_xpressive_expression_tag; Chris@16: //! This tag type is used if an expression is recognized as a Boost.Spirit (classic) expression Chris@16: struct boost_spirit_classic_expression_tag; Chris@16: //! This tag type is used if an expression is recognized as a Boost.Spirit.Qi expression Chris@16: struct boost_spirit_qi_expression_tag; Chris@16: Chris@16: //! Preliminary declaration of a trait that detects if an expression is a Boost.Regex expression Chris@16: template< typename, bool = true > Chris@16: struct is_regex : Chris@16: public mpl::false_ Chris@16: { Chris@16: }; Chris@16: //! Preliminary declaration of a trait that detects if an expression is a Boost.Xpressive expression Chris@16: template< typename, bool = true > Chris@16: struct is_xpressive_regex : Chris@16: public mpl::false_ Chris@16: { Chris@16: }; Chris@16: //! Preliminary declaration of a trait that detects if an expression is a Boost.Spirit (classic) expression Chris@16: template< typename, bool = true > Chris@16: struct is_spirit_classic_parser : Chris@16: public mpl::false_ Chris@16: { Chris@16: }; Chris@16: //! Preliminary declaration of a trait that detects if an expression is a Boost.Spirit.Qi expression Chris@16: template< typename, bool = true > Chris@16: struct is_spirit_qi_parser : Chris@16: public mpl::false_ Chris@16: { Chris@16: }; Chris@16: Chris@16: //! The regex matching functor implementation Chris@16: template< typename TagT > Chris@16: struct matches_fun_impl; Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: //! The regex matching functor Chris@16: struct matches_fun Chris@16: { Chris@16: typedef bool result_type; Chris@16: Chris@16: private: Chris@16: //! A traits to obtain the tag of the expression Chris@16: template< typename ExpressionT > Chris@16: struct match_traits Chris@16: { Chris@16: typedef typename mpl::eval_if< Chris@16: aux::is_regex< ExpressionT >, Chris@16: mpl::identity< aux::boost_regex_expression_tag >, Chris@16: mpl::eval_if< Chris@16: aux::is_xpressive_regex< ExpressionT >, Chris@16: mpl::identity< aux::boost_xpressive_expression_tag >, Chris@16: mpl::eval_if< Chris@16: aux::is_spirit_classic_parser< ExpressionT >, Chris@16: mpl::identity< aux::boost_spirit_classic_expression_tag >, Chris@16: mpl::if_< Chris@16: aux::is_spirit_qi_parser< ExpressionT >, Chris@16: aux::boost_spirit_qi_expression_tag, Chris@16: aux::unsupported_match_expression_tag Chris@16: > Chris@16: > Chris@16: > Chris@16: >::type tag_type; Chris@16: }; Chris@16: Chris@16: public: Chris@16: template< typename StringT, typename ExpressionT > Chris@16: bool operator() (StringT const& str, ExpressionT const& expr) const Chris@16: { Chris@16: typedef typename match_traits< ExpressionT >::tag_type tag_type; Chris@16: typedef aux::matches_fun_impl< tag_type > impl; Chris@16: return impl::matches(str, expr); Chris@16: } Chris@16: template< typename StringT, typename ExpressionT, typename ArgT > Chris@16: bool operator() (StringT const& str, ExpressionT const& expr, ArgT const& arg) const Chris@16: { Chris@16: typedef typename match_traits< ExpressionT >::tag_type tag_type; Chris@16: typedef aux::matches_fun_impl< tag_type > impl; Chris@16: return impl::matches(str, expr, arg); Chris@16: } Chris@16: }; Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_UTILITY_FUNCTIONAL_MATCHES_HPP_INCLUDED_