xpressive.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file support/xpressive.hpp
  9. * \author Andrey Semashev
  10. * \date 18.07.2009
  11. *
  12. * This header enables Boost.Xpressive support for Boost.Log.
  13. */
  14. #ifndef BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_
  15. #define BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_
  16. #include <string>
  17. #include <boost/xpressive/basic_regex.hpp>
  18. #include <boost/xpressive/regex_constants.hpp>
  19. #include <boost/xpressive/regex_algorithms.hpp>
  20. #include <boost/log/detail/config.hpp>
  21. #include <boost/log/utility/functional/matches.hpp>
  22. #include <boost/log/detail/header.hpp>
  23. #ifdef BOOST_HAS_PRAGMA_ONCE
  24. #pragma once
  25. #endif
  26. namespace boost {
  27. BOOST_LOG_OPEN_NAMESPACE
  28. namespace aux {
  29. //! This tag type is used if an expression is recognized as a Boost.Xpressive expression
  30. struct boost_xpressive_expression_tag;
  31. //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
  32. template< typename T >
  33. struct matching_expression_kind< xpressive::basic_regex< T > >
  34. {
  35. typedef boost_xpressive_expression_tag type;
  36. };
  37. //! The matching function implementation
  38. template< typename ExpressionT >
  39. struct match_traits< ExpressionT, boost_xpressive_expression_tag >
  40. {
  41. typedef ExpressionT compiled_type;
  42. static compiled_type compile(ExpressionT const& expr) { return expr; }
  43. template< typename StringT, typename T >
  44. static bool matches(StringT const& str, xpressive::basic_regex< T > const& expr, xpressive::regex_constants::match_flag_type flags = xpressive::regex_constants::match_default)
  45. {
  46. return xpressive::regex_match(str, expr, flags);
  47. }
  48. template< typename CharT, typename TraitsT, typename AllocatorT >
  49. static bool matches(std::basic_string< CharT, TraitsT, AllocatorT > const& str, xpressive::basic_regex< const CharT* > const& expr, xpressive::regex_constants::match_flag_type flags = xpressive::regex_constants::match_default)
  50. {
  51. const CharT* p = str.c_str();
  52. return xpressive::regex_match(p, p + str.size(), expr, flags);
  53. }
  54. };
  55. } // namespace aux
  56. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  57. } // namespace boost
  58. #include <boost/log/detail/footer.hpp>
  59. #endif // BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_