regex_traits.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. *
  3. * Copyright (c) 2003
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. /*
  12. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE regex_traits.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Declares regular expression traits classes.
  16. */
  17. #ifndef BOOST_REGEX_TRAITS_HPP_INCLUDED
  18. #define BOOST_REGEX_TRAITS_HPP_INCLUDED
  19. #include <boost/regex/config.hpp>
  20. #include <boost/regex/v5/regex_workaround.hpp>
  21. #include <boost/regex/v5/syntax_type.hpp>
  22. #include <boost/regex/v5/error_type.hpp>
  23. #include <boost/regex/v5/regex_traits_defaults.hpp>
  24. #include <boost/regex/v5/cpp_regex_traits.hpp>
  25. #include <boost/regex/v5/c_regex_traits.hpp>
  26. #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
  27. # include <boost/regex/v5/w32_regex_traits.hpp>
  28. #endif
  29. #include <boost/regex_fwd.hpp>
  30. namespace boost{
  31. template <class charT, class implementationT >
  32. struct regex_traits : public implementationT
  33. {
  34. regex_traits() : implementationT() {}
  35. };
  36. //
  37. // class regex_traits_wrapper.
  38. // this is what our implementation will actually store;
  39. // it provides default implementations of the "optional"
  40. // interfaces that we support, in addition to the
  41. // required "standard" ones:
  42. //
  43. namespace BOOST_REGEX_DETAIL_NS{
  44. template <class T>
  45. struct has_boost_extensions_tag
  46. {
  47. template <class U>
  48. static double checker(U*, typename U::boost_extensions_tag* = nullptr);
  49. static char checker(...);
  50. static T* get();
  51. static const bool value = sizeof(checker(get())) > 1;
  52. };
  53. template <class BaseT>
  54. struct default_wrapper : public BaseT
  55. {
  56. typedef typename BaseT::char_type char_type;
  57. std::string error_string(::boost::regex_constants::error_type e)const
  58. {
  59. return ::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(e);
  60. }
  61. ::boost::regex_constants::syntax_type syntax_type(char_type c)const
  62. {
  63. return (char_type(c & 0x7f) == c) ? get_default_syntax_type(static_cast<char>(c)) : ::boost::regex_constants::syntax_char;
  64. }
  65. ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c)const
  66. {
  67. return (char_type(c & 0x7f) == c) ? get_default_escape_syntax_type(static_cast<char>(c)) : ::boost::regex_constants::escape_type_identity;
  68. }
  69. std::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
  70. {
  71. return ::boost::BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
  72. }
  73. char_type translate(char_type c, bool icase)const
  74. {
  75. return (icase ? this->translate_nocase(c) : this->translate(c));
  76. }
  77. char_type translate(char_type c)const
  78. {
  79. return BaseT::translate(c);
  80. }
  81. char_type tolower(char_type c)const
  82. {
  83. return ::boost::BOOST_REGEX_DETAIL_NS::global_lower(c);
  84. }
  85. char_type toupper(char_type c)const
  86. {
  87. return ::boost::BOOST_REGEX_DETAIL_NS::global_upper(c);
  88. }
  89. };
  90. template <class BaseT, bool has_extensions>
  91. struct compute_wrapper_base
  92. {
  93. typedef BaseT type;
  94. };
  95. template <class BaseT>
  96. struct compute_wrapper_base<BaseT, false>
  97. {
  98. typedef default_wrapper<BaseT> type;
  99. };
  100. } // namespace BOOST_REGEX_DETAIL_NS
  101. template <class BaseT>
  102. struct regex_traits_wrapper
  103. : public ::boost::BOOST_REGEX_DETAIL_NS::compute_wrapper_base<
  104. BaseT,
  105. ::boost::BOOST_REGEX_DETAIL_NS::has_boost_extensions_tag<BaseT>::value
  106. >::type
  107. {
  108. regex_traits_wrapper(){}
  109. private:
  110. regex_traits_wrapper(const regex_traits_wrapper&);
  111. regex_traits_wrapper& operator=(const regex_traits_wrapper&);
  112. };
  113. } // namespace boost
  114. #endif // include