Chris@16
|
1 /*
|
Chris@16
|
2 *
|
Chris@16
|
3 * Copyright (c) 2004
|
Chris@16
|
4 * John Maddock
|
Chris@16
|
5 *
|
Chris@16
|
6 * Use, modification and distribution are subject to the
|
Chris@16
|
7 * Boost Software License, Version 1.0. (See accompanying file
|
Chris@16
|
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 *
|
Chris@16
|
10 */
|
Chris@16
|
11
|
Chris@16
|
12 /*
|
Chris@16
|
13 * LOCATION: see http://www.boost.org for most recent version.
|
Chris@16
|
14 * FILE c_regex_traits.hpp
|
Chris@16
|
15 * VERSION see <boost/version.hpp>
|
Chris@16
|
16 * DESCRIPTION: Declares regular expression traits class that wraps the global C locale.
|
Chris@16
|
17 */
|
Chris@16
|
18
|
Chris@16
|
19 #ifndef BOOST_C_REGEX_TRAITS_HPP_INCLUDED
|
Chris@16
|
20 #define BOOST_C_REGEX_TRAITS_HPP_INCLUDED
|
Chris@16
|
21
|
Chris@16
|
22 #ifndef BOOST_REGEX_CONFIG_HPP
|
Chris@16
|
23 #include <boost/regex/config.hpp>
|
Chris@16
|
24 #endif
|
Chris@16
|
25 #ifndef BOOST_REGEX_WORKAROUND_HPP
|
Chris@16
|
26 #include <boost/regex/v4/regex_workaround.hpp>
|
Chris@16
|
27 #endif
|
Chris@16
|
28
|
Chris@16
|
29 #include <cctype>
|
Chris@16
|
30
|
Chris@16
|
31 #ifdef BOOST_NO_STDC_NAMESPACE
|
Chris@16
|
32 namespace std{
|
Chris@16
|
33 using ::strlen; using ::tolower;
|
Chris@16
|
34 }
|
Chris@16
|
35 #endif
|
Chris@16
|
36
|
Chris@16
|
37 #ifdef BOOST_MSVC
|
Chris@16
|
38 #pragma warning(push)
|
Chris@16
|
39 #pragma warning(disable: 4103)
|
Chris@16
|
40 #endif
|
Chris@16
|
41 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
42 # include BOOST_ABI_PREFIX
|
Chris@16
|
43 #endif
|
Chris@16
|
44 #ifdef BOOST_MSVC
|
Chris@16
|
45 #pragma warning(pop)
|
Chris@16
|
46 #endif
|
Chris@16
|
47
|
Chris@16
|
48 namespace boost{
|
Chris@16
|
49
|
Chris@16
|
50 template <class charT>
|
Chris@16
|
51 struct c_regex_traits;
|
Chris@16
|
52
|
Chris@16
|
53 template<>
|
Chris@16
|
54 struct BOOST_REGEX_DECL c_regex_traits<char>
|
Chris@16
|
55 {
|
Chris@16
|
56 c_regex_traits(){}
|
Chris@16
|
57 typedef char char_type;
|
Chris@16
|
58 typedef std::size_t size_type;
|
Chris@16
|
59 typedef std::string string_type;
|
Chris@16
|
60 struct locale_type{};
|
Chris@16
|
61 typedef boost::uint32_t char_class_type;
|
Chris@16
|
62
|
Chris@16
|
63 static size_type length(const char_type* p)
|
Chris@16
|
64 {
|
Chris@16
|
65 return (std::strlen)(p);
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 char translate(char c) const
|
Chris@16
|
69 {
|
Chris@16
|
70 return c;
|
Chris@16
|
71 }
|
Chris@16
|
72 char translate_nocase(char c) const
|
Chris@16
|
73 {
|
Chris@16
|
74 return static_cast<char>((std::tolower)(static_cast<unsigned char>(c)));
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 static string_type BOOST_REGEX_CALL transform(const char* p1, const char* p2);
|
Chris@16
|
78 static string_type BOOST_REGEX_CALL transform_primary(const char* p1, const char* p2);
|
Chris@16
|
79
|
Chris@16
|
80 static char_class_type BOOST_REGEX_CALL lookup_classname(const char* p1, const char* p2);
|
Chris@16
|
81 static string_type BOOST_REGEX_CALL lookup_collatename(const char* p1, const char* p2);
|
Chris@16
|
82
|
Chris@16
|
83 static bool BOOST_REGEX_CALL isctype(char, char_class_type);
|
Chris@16
|
84 static int BOOST_REGEX_CALL value(char, int);
|
Chris@16
|
85
|
Chris@16
|
86 locale_type imbue(locale_type l)
|
Chris@16
|
87 { return l; }
|
Chris@16
|
88 locale_type getloc()const
|
Chris@16
|
89 { return locale_type(); }
|
Chris@16
|
90
|
Chris@16
|
91 private:
|
Chris@16
|
92 // this type is not copyable:
|
Chris@16
|
93 c_regex_traits(const c_regex_traits&);
|
Chris@16
|
94 c_regex_traits& operator=(const c_regex_traits&);
|
Chris@16
|
95 };
|
Chris@16
|
96
|
Chris@16
|
97 #ifndef BOOST_NO_WREGEX
|
Chris@16
|
98 template<>
|
Chris@16
|
99 struct BOOST_REGEX_DECL c_regex_traits<wchar_t>
|
Chris@16
|
100 {
|
Chris@16
|
101 c_regex_traits(){}
|
Chris@16
|
102 typedef wchar_t char_type;
|
Chris@16
|
103 typedef std::size_t size_type;
|
Chris@16
|
104 typedef std::wstring string_type;
|
Chris@16
|
105 struct locale_type{};
|
Chris@16
|
106 typedef boost::uint32_t char_class_type;
|
Chris@16
|
107
|
Chris@16
|
108 static size_type length(const char_type* p)
|
Chris@16
|
109 {
|
Chris@16
|
110 return (std::wcslen)(p);
|
Chris@16
|
111 }
|
Chris@16
|
112
|
Chris@16
|
113 wchar_t translate(wchar_t c) const
|
Chris@16
|
114 {
|
Chris@16
|
115 return c;
|
Chris@16
|
116 }
|
Chris@16
|
117 wchar_t translate_nocase(wchar_t c) const
|
Chris@16
|
118 {
|
Chris@16
|
119 return (std::towlower)(c);
|
Chris@16
|
120 }
|
Chris@16
|
121
|
Chris@16
|
122 static string_type BOOST_REGEX_CALL transform(const wchar_t* p1, const wchar_t* p2);
|
Chris@16
|
123 static string_type BOOST_REGEX_CALL transform_primary(const wchar_t* p1, const wchar_t* p2);
|
Chris@16
|
124
|
Chris@16
|
125 static char_class_type BOOST_REGEX_CALL lookup_classname(const wchar_t* p1, const wchar_t* p2);
|
Chris@16
|
126 static string_type BOOST_REGEX_CALL lookup_collatename(const wchar_t* p1, const wchar_t* p2);
|
Chris@16
|
127
|
Chris@16
|
128 static bool BOOST_REGEX_CALL isctype(wchar_t, char_class_type);
|
Chris@16
|
129 static int BOOST_REGEX_CALL value(wchar_t, int);
|
Chris@16
|
130
|
Chris@16
|
131 locale_type imbue(locale_type l)
|
Chris@16
|
132 { return l; }
|
Chris@16
|
133 locale_type getloc()const
|
Chris@16
|
134 { return locale_type(); }
|
Chris@16
|
135
|
Chris@16
|
136 private:
|
Chris@16
|
137 // this type is not copyable:
|
Chris@16
|
138 c_regex_traits(const c_regex_traits&);
|
Chris@16
|
139 c_regex_traits& operator=(const c_regex_traits&);
|
Chris@16
|
140 };
|
Chris@16
|
141
|
Chris@16
|
142 #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
Chris@16
|
143 //
|
Chris@16
|
144 // Provide an unsigned short version as well, so the user can link to this
|
Chris@16
|
145 // no matter whether they build with /Zc:wchar_t or not (MSVC specific).
|
Chris@16
|
146 //
|
Chris@16
|
147 template<>
|
Chris@16
|
148 struct BOOST_REGEX_DECL c_regex_traits<unsigned short>
|
Chris@16
|
149 {
|
Chris@16
|
150 c_regex_traits(){}
|
Chris@16
|
151 typedef unsigned short char_type;
|
Chris@16
|
152 typedef std::size_t size_type;
|
Chris@16
|
153 typedef std::basic_string<unsigned short> string_type;
|
Chris@16
|
154 struct locale_type{};
|
Chris@16
|
155 typedef boost::uint32_t char_class_type;
|
Chris@16
|
156
|
Chris@16
|
157 static size_type length(const char_type* p)
|
Chris@16
|
158 {
|
Chris@16
|
159 return (std::wcslen)((const wchar_t*)p);
|
Chris@16
|
160 }
|
Chris@16
|
161
|
Chris@16
|
162 unsigned short translate(unsigned short c) const
|
Chris@16
|
163 {
|
Chris@16
|
164 return c;
|
Chris@16
|
165 }
|
Chris@16
|
166 unsigned short translate_nocase(unsigned short c) const
|
Chris@16
|
167 {
|
Chris@16
|
168 return (std::towlower)((wchar_t)c);
|
Chris@16
|
169 }
|
Chris@16
|
170
|
Chris@16
|
171 static string_type BOOST_REGEX_CALL transform(const unsigned short* p1, const unsigned short* p2);
|
Chris@16
|
172 static string_type BOOST_REGEX_CALL transform_primary(const unsigned short* p1, const unsigned short* p2);
|
Chris@16
|
173
|
Chris@16
|
174 static char_class_type BOOST_REGEX_CALL lookup_classname(const unsigned short* p1, const unsigned short* p2);
|
Chris@16
|
175 static string_type BOOST_REGEX_CALL lookup_collatename(const unsigned short* p1, const unsigned short* p2);
|
Chris@16
|
176
|
Chris@16
|
177 static bool BOOST_REGEX_CALL isctype(unsigned short, char_class_type);
|
Chris@16
|
178 static int BOOST_REGEX_CALL value(unsigned short, int);
|
Chris@16
|
179
|
Chris@16
|
180 locale_type imbue(locale_type l)
|
Chris@16
|
181 { return l; }
|
Chris@16
|
182 locale_type getloc()const
|
Chris@16
|
183 { return locale_type(); }
|
Chris@16
|
184
|
Chris@16
|
185 private:
|
Chris@16
|
186 // this type is not copyable:
|
Chris@16
|
187 c_regex_traits(const c_regex_traits&);
|
Chris@16
|
188 c_regex_traits& operator=(const c_regex_traits&);
|
Chris@16
|
189 };
|
Chris@16
|
190
|
Chris@16
|
191 #endif
|
Chris@16
|
192
|
Chris@16
|
193 #endif // BOOST_NO_WREGEX
|
Chris@16
|
194
|
Chris@16
|
195 }
|
Chris@16
|
196
|
Chris@16
|
197 #ifdef BOOST_MSVC
|
Chris@16
|
198 #pragma warning(push)
|
Chris@16
|
199 #pragma warning(disable: 4103)
|
Chris@16
|
200 #endif
|
Chris@16
|
201 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
202 # include BOOST_ABI_SUFFIX
|
Chris@16
|
203 #endif
|
Chris@16
|
204 #ifdef BOOST_MSVC
|
Chris@16
|
205 #pragma warning(pop)
|
Chris@16
|
206 #endif
|
Chris@16
|
207
|
Chris@16
|
208 #endif
|
Chris@16
|
209
|
Chris@16
|
210
|
Chris@16
|
211
|