c_regex_traits.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. *
  3. * Copyright (c) 2004
  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 c_regex_traits.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Declares regular expression traits class that wraps the global C locale.
  16. */
  17. #ifndef BOOST_C_REGEX_TRAITS_HPP_INCLUDED
  18. #define BOOST_C_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. #include <cctype>
  26. #ifdef BOOST_NO_STDC_NAMESPACE
  27. namespace std{
  28. using ::strlen; using ::tolower;
  29. }
  30. #endif
  31. #ifdef BOOST_MSVC
  32. #pragma warning(push)
  33. #pragma warning(disable: 4103)
  34. #endif
  35. #ifdef BOOST_HAS_ABI_HEADERS
  36. # include BOOST_ABI_PREFIX
  37. #endif
  38. #ifdef BOOST_MSVC
  39. #pragma warning(pop)
  40. #endif
  41. namespace boost{
  42. template <class charT>
  43. struct c_regex_traits;
  44. template<>
  45. struct BOOST_REGEX_DECL c_regex_traits<char>
  46. {
  47. c_regex_traits(){}
  48. typedef char char_type;
  49. typedef std::size_t size_type;
  50. typedef std::string string_type;
  51. struct locale_type{};
  52. typedef boost::uint32_t char_class_type;
  53. static size_type length(const char_type* p)
  54. {
  55. return (std::strlen)(p);
  56. }
  57. char translate(char c) const
  58. {
  59. return c;
  60. }
  61. char translate_nocase(char c) const
  62. {
  63. return static_cast<char>((std::tolower)(static_cast<unsigned char>(c)));
  64. }
  65. static string_type BOOST_REGEX_CALL transform(const char* p1, const char* p2);
  66. static string_type BOOST_REGEX_CALL transform_primary(const char* p1, const char* p2);
  67. static char_class_type BOOST_REGEX_CALL lookup_classname(const char* p1, const char* p2);
  68. static string_type BOOST_REGEX_CALL lookup_collatename(const char* p1, const char* p2);
  69. static bool BOOST_REGEX_CALL isctype(char, char_class_type);
  70. static int BOOST_REGEX_CALL value(char, int);
  71. locale_type imbue(locale_type l)
  72. { return l; }
  73. locale_type getloc()const
  74. { return locale_type(); }
  75. private:
  76. // this type is not copyable:
  77. c_regex_traits(const c_regex_traits&);
  78. c_regex_traits& operator=(const c_regex_traits&);
  79. };
  80. #ifndef BOOST_NO_WREGEX
  81. template<>
  82. struct BOOST_REGEX_DECL c_regex_traits<wchar_t>
  83. {
  84. c_regex_traits(){}
  85. typedef wchar_t char_type;
  86. typedef std::size_t size_type;
  87. typedef std::wstring string_type;
  88. struct locale_type{};
  89. typedef boost::uint32_t char_class_type;
  90. static size_type length(const char_type* p)
  91. {
  92. return (std::wcslen)(p);
  93. }
  94. wchar_t translate(wchar_t c) const
  95. {
  96. return c;
  97. }
  98. wchar_t translate_nocase(wchar_t c) const
  99. {
  100. return (std::towlower)(c);
  101. }
  102. static string_type BOOST_REGEX_CALL transform(const wchar_t* p1, const wchar_t* p2);
  103. static string_type BOOST_REGEX_CALL transform_primary(const wchar_t* p1, const wchar_t* p2);
  104. static char_class_type BOOST_REGEX_CALL lookup_classname(const wchar_t* p1, const wchar_t* p2);
  105. static string_type BOOST_REGEX_CALL lookup_collatename(const wchar_t* p1, const wchar_t* p2);
  106. static bool BOOST_REGEX_CALL isctype(wchar_t, char_class_type);
  107. static int BOOST_REGEX_CALL value(wchar_t, int);
  108. locale_type imbue(locale_type l)
  109. { return l; }
  110. locale_type getloc()const
  111. { return locale_type(); }
  112. private:
  113. // this type is not copyable:
  114. c_regex_traits(const c_regex_traits&);
  115. c_regex_traits& operator=(const c_regex_traits&);
  116. };
  117. #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
  118. //
  119. // Provide an unsigned short version as well, so the user can link to this
  120. // no matter whether they build with /Zc:wchar_t or not (MSVC specific).
  121. //
  122. template<>
  123. struct BOOST_REGEX_DECL c_regex_traits<unsigned short>
  124. {
  125. c_regex_traits(){}
  126. typedef unsigned short char_type;
  127. typedef std::size_t size_type;
  128. typedef std::basic_string<unsigned short> string_type;
  129. struct locale_type{};
  130. typedef boost::uint32_t char_class_type;
  131. static size_type length(const char_type* p)
  132. {
  133. return (std::wcslen)((const wchar_t*)p);
  134. }
  135. unsigned short translate(unsigned short c) const
  136. {
  137. return c;
  138. }
  139. unsigned short translate_nocase(unsigned short c) const
  140. {
  141. return (std::towlower)((wchar_t)c);
  142. }
  143. static string_type BOOST_REGEX_CALL transform(const unsigned short* p1, const unsigned short* p2);
  144. static string_type BOOST_REGEX_CALL transform_primary(const unsigned short* p1, const unsigned short* p2);
  145. static char_class_type BOOST_REGEX_CALL lookup_classname(const unsigned short* p1, const unsigned short* p2);
  146. static string_type BOOST_REGEX_CALL lookup_collatename(const unsigned short* p1, const unsigned short* p2);
  147. static bool BOOST_REGEX_CALL isctype(unsigned short, char_class_type);
  148. static int BOOST_REGEX_CALL value(unsigned short, int);
  149. locale_type imbue(locale_type l)
  150. { return l; }
  151. locale_type getloc()const
  152. { return locale_type(); }
  153. private:
  154. // this type is not copyable:
  155. c_regex_traits(const c_regex_traits&);
  156. c_regex_traits& operator=(const c_regex_traits&);
  157. };
  158. #endif
  159. #endif // BOOST_NO_WREGEX
  160. }
  161. #ifdef BOOST_MSVC
  162. #pragma warning(push)
  163. #pragma warning(disable: 4103)
  164. #endif
  165. #ifdef BOOST_HAS_ABI_HEADERS
  166. # include BOOST_ABI_SUFFIX
  167. #endif
  168. #ifdef BOOST_MSVC
  169. #pragma warning(pop)
  170. #endif
  171. #endif