regex_traits.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #ifndef BOOST_REGEX_CONFIG_HPP
  20. #include <boost/regex/config.hpp>
  21. #endif
  22. #ifndef BOOST_REGEX_WORKAROUND_HPP
  23. #include <boost/regex/v4/regex_workaround.hpp>
  24. #endif
  25. #ifndef BOOST_REGEX_SYNTAX_TYPE_HPP
  26. #include <boost/regex/v4/syntax_type.hpp>
  27. #endif
  28. #ifndef BOOST_REGEX_ERROR_TYPE_HPP
  29. #include <boost/regex/v4/error_type.hpp>
  30. #endif
  31. #ifndef BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
  32. #include <boost/regex/v4/regex_traits_defaults.hpp>
  33. #endif
  34. #ifndef BOOST_NO_STD_LOCALE
  35. # ifndef BOOST_CPP_REGEX_TRAITS_HPP_INCLUDED
  36. # include <boost/regex/v4/cpp_regex_traits.hpp>
  37. # endif
  38. #endif
  39. #if !BOOST_WORKAROUND(BOOST_BORLANDC, < 0x560)
  40. # ifndef BOOST_C_REGEX_TRAITS_HPP_INCLUDED
  41. # include <boost/regex/v4/c_regex_traits.hpp>
  42. # endif
  43. #endif
  44. #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
  45. # ifndef BOOST_W32_REGEX_TRAITS_HPP_INCLUDED
  46. # include <boost/regex/v4/w32_regex_traits.hpp>
  47. # endif
  48. #endif
  49. #ifndef BOOST_REGEX_FWD_HPP_INCLUDED
  50. #include <boost/regex_fwd.hpp>
  51. #endif
  52. #include "boost/mpl/has_xxx.hpp"
  53. #include <boost/static_assert.hpp>
  54. #ifdef BOOST_MSVC
  55. #pragma warning(push)
  56. #pragma warning(disable: 4103)
  57. #endif
  58. #ifdef BOOST_HAS_ABI_HEADERS
  59. # include BOOST_ABI_PREFIX
  60. #endif
  61. #ifdef BOOST_MSVC
  62. #pragma warning(pop)
  63. #endif
  64. namespace boost{
  65. template <class charT, class implementationT >
  66. struct regex_traits : public implementationT
  67. {
  68. regex_traits() : implementationT() {}
  69. };
  70. //
  71. // class regex_traits_wrapper.
  72. // this is what our implementation will actually store;
  73. // it provides default implementations of the "optional"
  74. // interfaces that we support, in addition to the
  75. // required "standard" ones:
  76. //
  77. namespace BOOST_REGEX_DETAIL_NS{
  78. #if !BOOST_WORKAROUND(__HP_aCC, < 60000)
  79. BOOST_MPL_HAS_XXX_TRAIT_DEF(boost_extensions_tag)
  80. #else
  81. template<class T>
  82. struct has_boost_extensions_tag
  83. {
  84. BOOST_STATIC_CONSTANT(bool, value = false);
  85. };
  86. #endif
  87. template <class BaseT>
  88. struct default_wrapper : public BaseT
  89. {
  90. typedef typename BaseT::char_type char_type;
  91. std::string error_string(::boost::regex_constants::error_type e)const
  92. {
  93. return ::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(e);
  94. }
  95. ::boost::regex_constants::syntax_type syntax_type(char_type c)const
  96. {
  97. return ((c & 0x7f) == c) ? get_default_syntax_type(static_cast<char>(c)) : ::boost::regex_constants::syntax_char;
  98. }
  99. ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c)const
  100. {
  101. return ((c & 0x7f) == c) ? get_default_escape_syntax_type(static_cast<char>(c)) : ::boost::regex_constants::escape_type_identity;
  102. }
  103. boost::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
  104. {
  105. return ::boost::BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
  106. }
  107. char_type translate(char_type c, bool icase)const
  108. {
  109. return (icase ? this->translate_nocase(c) : this->translate(c));
  110. }
  111. char_type translate(char_type c)const
  112. {
  113. return BaseT::translate(c);
  114. }
  115. char_type tolower(char_type c)const
  116. {
  117. return ::boost::BOOST_REGEX_DETAIL_NS::global_lower(c);
  118. }
  119. char_type toupper(char_type c)const
  120. {
  121. return ::boost::BOOST_REGEX_DETAIL_NS::global_upper(c);
  122. }
  123. };
  124. template <class BaseT, bool has_extensions>
  125. struct compute_wrapper_base
  126. {
  127. typedef BaseT type;
  128. };
  129. #if !BOOST_WORKAROUND(__HP_aCC, < 60000)
  130. template <class BaseT>
  131. struct compute_wrapper_base<BaseT, false>
  132. {
  133. typedef default_wrapper<BaseT> type;
  134. };
  135. #else
  136. template <>
  137. struct compute_wrapper_base<c_regex_traits<char>, false>
  138. {
  139. typedef default_wrapper<c_regex_traits<char> > type;
  140. };
  141. #ifndef BOOST_NO_WREGEX
  142. template <>
  143. struct compute_wrapper_base<c_regex_traits<wchar_t>, false>
  144. {
  145. typedef default_wrapper<c_regex_traits<wchar_t> > type;
  146. };
  147. #endif
  148. #endif
  149. } // namespace BOOST_REGEX_DETAIL_NS
  150. template <class BaseT>
  151. struct regex_traits_wrapper
  152. : public ::boost::BOOST_REGEX_DETAIL_NS::compute_wrapper_base<
  153. BaseT,
  154. ::boost::BOOST_REGEX_DETAIL_NS::has_boost_extensions_tag<BaseT>::value
  155. >::type
  156. {
  157. regex_traits_wrapper(){}
  158. private:
  159. regex_traits_wrapper(const regex_traits_wrapper&);
  160. regex_traits_wrapper& operator=(const regex_traits_wrapper&);
  161. };
  162. } // namespace boost
  163. #ifdef BOOST_MSVC
  164. #pragma warning(push)
  165. #pragma warning(disable: 4103)
  166. #endif
  167. #ifdef BOOST_HAS_ABI_HEADERS
  168. # include BOOST_ABI_SUFFIX
  169. #endif
  170. #ifdef BOOST_MSVC
  171. #pragma warning(pop)
  172. #endif
  173. #endif // include