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 /* 13 * LOCATION: see http://www.boost.org for most recent version. 14 * FILE c_regex_traits.hpp 15 * VERSION see <boost/version.hpp> 16 * DESCRIPTION: Declares regular expression traits class that wraps the global C locale. 17 */ 18 19 #ifndef BOOST_C_REGEX_TRAITS_HPP_INCLUDED 20 #define BOOST_C_REGEX_TRAITS_HPP_INCLUDED 21 22 #ifndef BOOST_REGEX_CONFIG_HPP 23 #include <boost/regex/config.hpp> 24 #endif 25 #ifndef BOOST_REGEX_WORKAROUND_HPP 26 #include <boost/regex/v4/regex_workaround.hpp> 27 #endif 28 29 #include <cctype> 30 31 #ifdef BOOST_NO_STDC_NAMESPACE 32 namespace std{ 33 using ::strlen; using ::tolower; 34 } 35 #endif 36 37 #ifdef BOOST_MSVC 38 #pragma warning(push) 39 #pragma warning(disable: 4103) 40 #endif 41 #ifdef BOOST_HAS_ABI_HEADERS 42 # include BOOST_ABI_PREFIX 43 #endif 44 #ifdef BOOST_MSVC 45 #pragma warning(pop) 46 #endif 47 48 namespace boost{ 49 50 template <class charT> 51 struct c_regex_traits; 52 53 template<> 54 struct BOOST_REGEX_DECL c_regex_traits<char> 55 { c_regex_traitsboost::c_regex_traits56 c_regex_traits(){} 57 typedef char char_type; 58 typedef std::size_t size_type; 59 typedef std::string string_type; 60 struct locale_type{}; 61 typedef boost::uint32_t char_class_type; 62 lengthboost::c_regex_traits63 static size_type length(const char_type* p) 64 { 65 return (std::strlen)(p); 66 } 67 translateboost::c_regex_traits68 char translate(char c) const 69 { 70 return c; 71 } translate_nocaseboost::c_regex_traits72 char translate_nocase(char c) const 73 { 74 return static_cast<char>((std::tolower)(static_cast<unsigned char>(c))); 75 } 76 77 static string_type BOOST_REGEX_CALL transform(const char* p1, const char* p2); 78 static string_type BOOST_REGEX_CALL transform_primary(const char* p1, const char* p2); 79 80 static char_class_type BOOST_REGEX_CALL lookup_classname(const char* p1, const char* p2); 81 static string_type BOOST_REGEX_CALL lookup_collatename(const char* p1, const char* p2); 82 83 static bool BOOST_REGEX_CALL isctype(char, char_class_type); 84 static int BOOST_REGEX_CALL value(char, int); 85 imbueboost::c_regex_traits86 locale_type imbue(locale_type l) 87 { return l; } getlocboost::c_regex_traits88 locale_type getloc()const 89 { return locale_type(); } 90 91 private: 92 // this type is not copyable: 93 c_regex_traits(const c_regex_traits&); 94 c_regex_traits& operator=(const c_regex_traits&); 95 }; 96 97 #ifndef BOOST_NO_WREGEX 98 template<> 99 struct BOOST_REGEX_DECL c_regex_traits<wchar_t> 100 { c_regex_traitsboost::c_regex_traits101 c_regex_traits(){} 102 typedef wchar_t char_type; 103 typedef std::size_t size_type; 104 typedef std::wstring string_type; 105 struct locale_type{}; 106 typedef boost::uint32_t char_class_type; 107 lengthboost::c_regex_traits108 static size_type length(const char_type* p) 109 { 110 return (std::wcslen)(p); 111 } 112 translateboost::c_regex_traits113 wchar_t translate(wchar_t c) const 114 { 115 return c; 116 } translate_nocaseboost::c_regex_traits117 wchar_t translate_nocase(wchar_t c) const 118 { 119 return (std::towlower)(c); 120 } 121 122 static string_type BOOST_REGEX_CALL transform(const wchar_t* p1, const wchar_t* p2); 123 static string_type BOOST_REGEX_CALL transform_primary(const wchar_t* p1, const wchar_t* p2); 124 125 static char_class_type BOOST_REGEX_CALL lookup_classname(const wchar_t* p1, const wchar_t* p2); 126 static string_type BOOST_REGEX_CALL lookup_collatename(const wchar_t* p1, const wchar_t* p2); 127 128 static bool BOOST_REGEX_CALL isctype(wchar_t, char_class_type); 129 static int BOOST_REGEX_CALL value(wchar_t, int); 130 imbueboost::c_regex_traits131 locale_type imbue(locale_type l) 132 { return l; } getlocboost::c_regex_traits133 locale_type getloc()const 134 { return locale_type(); } 135 136 private: 137 // this type is not copyable: 138 c_regex_traits(const c_regex_traits&); 139 c_regex_traits& operator=(const c_regex_traits&); 140 }; 141 142 #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T 143 // 144 // Provide an unsigned short version as well, so the user can link to this 145 // no matter whether they build with /Zc:wchar_t or not (MSVC specific). 146 // 147 template<> 148 struct BOOST_REGEX_DECL c_regex_traits<unsigned short> 149 { c_regex_traitsboost::c_regex_traits150 c_regex_traits(){} 151 typedef unsigned short char_type; 152 typedef std::size_t size_type; 153 typedef std::basic_string<unsigned short> string_type; 154 struct locale_type{}; 155 typedef boost::uint32_t char_class_type; 156 lengthboost::c_regex_traits157 static size_type length(const char_type* p) 158 { 159 return (std::wcslen)((const wchar_t*)p); 160 } 161 translateboost::c_regex_traits162 unsigned short translate(unsigned short c) const 163 { 164 return c; 165 } translate_nocaseboost::c_regex_traits166 unsigned short translate_nocase(unsigned short c) const 167 { 168 return (std::towlower)((wchar_t)c); 169 } 170 171 static string_type BOOST_REGEX_CALL transform(const unsigned short* p1, const unsigned short* p2); 172 static string_type BOOST_REGEX_CALL transform_primary(const unsigned short* p1, const unsigned short* p2); 173 174 static char_class_type BOOST_REGEX_CALL lookup_classname(const unsigned short* p1, const unsigned short* p2); 175 static string_type BOOST_REGEX_CALL lookup_collatename(const unsigned short* p1, const unsigned short* p2); 176 177 static bool BOOST_REGEX_CALL isctype(unsigned short, char_class_type); 178 static int BOOST_REGEX_CALL value(unsigned short, int); 179 imbueboost::c_regex_traits180 locale_type imbue(locale_type l) 181 { return l; } getlocboost::c_regex_traits182 locale_type getloc()const 183 { return locale_type(); } 184 185 private: 186 // this type is not copyable: 187 c_regex_traits(const c_regex_traits&); 188 c_regex_traits& operator=(const c_regex_traits&); 189 }; 190 191 #endif 192 193 #endif // BOOST_NO_WREGEX 194 195 } 196 197 #ifdef BOOST_MSVC 198 #pragma warning(push) 199 #pragma warning(disable: 4103) 200 #endif 201 #ifdef BOOST_HAS_ABI_HEADERS 202 # include BOOST_ABI_SUFFIX 203 #endif 204 #ifdef BOOST_MSVC 205 #pragma warning(pop) 206 #endif 207 208 #endif 209 210 211 212