Chris@16
|
1 /*
|
Chris@16
|
2 *
|
Chris@16
|
3 * Copyright (c) 1998-2002
|
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 regex_match.hpp
|
Chris@16
|
15 * VERSION see <boost/version.hpp>
|
Chris@16
|
16 * DESCRIPTION: Regular expression matching algorithms.
|
Chris@16
|
17 * Note this is an internal header file included
|
Chris@16
|
18 * by regex.hpp, do not include on its own.
|
Chris@16
|
19 */
|
Chris@16
|
20
|
Chris@16
|
21
|
Chris@16
|
22 #ifndef BOOST_REGEX_MATCH_HPP
|
Chris@16
|
23 #define BOOST_REGEX_MATCH_HPP
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost{
|
Chris@16
|
26
|
Chris@16
|
27 #ifdef BOOST_MSVC
|
Chris@16
|
28 #pragma warning(push)
|
Chris@16
|
29 #pragma warning(disable: 4103)
|
Chris@16
|
30 #endif
|
Chris@16
|
31 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
32 # include BOOST_ABI_PREFIX
|
Chris@16
|
33 #endif
|
Chris@16
|
34 #ifdef BOOST_MSVC
|
Chris@16
|
35 #pragma warning(pop)
|
Chris@16
|
36 #endif
|
Chris@16
|
37
|
Chris@16
|
38 //
|
Chris@16
|
39 // proc regex_match
|
Chris@16
|
40 // returns true if the specified regular expression matches
|
Chris@16
|
41 // the whole of the input. Fills in what matched in m.
|
Chris@16
|
42 //
|
Chris@16
|
43 template <class BidiIterator, class Allocator, class charT, class traits>
|
Chris@16
|
44 bool regex_match(BidiIterator first, BidiIterator last,
|
Chris@16
|
45 match_results<BidiIterator, Allocator>& m,
|
Chris@16
|
46 const basic_regex<charT, traits>& e,
|
Chris@16
|
47 match_flag_type flags = match_default)
|
Chris@16
|
48 {
|
Chris@16
|
49 re_detail::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, first);
|
Chris@16
|
50 return matcher.match();
|
Chris@16
|
51 }
|
Chris@16
|
52 template <class iterator, class charT, class traits>
|
Chris@16
|
53 bool regex_match(iterator first, iterator last,
|
Chris@16
|
54 const basic_regex<charT, traits>& e,
|
Chris@16
|
55 match_flag_type flags = match_default)
|
Chris@16
|
56 {
|
Chris@16
|
57 match_results<iterator> m;
|
Chris@16
|
58 return regex_match(first, last, m, e, flags | regex_constants::match_any);
|
Chris@16
|
59 }
|
Chris@16
|
60 //
|
Chris@16
|
61 // query_match convenience interfaces:
|
Chris@16
|
62 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
Chris@16
|
63 //
|
Chris@16
|
64 // this isn't really a partial specialisation, but template function
|
Chris@16
|
65 // overloading - if the compiler doesn't support partial specialisation
|
Chris@16
|
66 // then it really won't support this either:
|
Chris@16
|
67 template <class charT, class Allocator, class traits>
|
Chris@16
|
68 inline bool regex_match(const charT* str,
|
Chris@16
|
69 match_results<const charT*, Allocator>& m,
|
Chris@16
|
70 const basic_regex<charT, traits>& e,
|
Chris@16
|
71 match_flag_type flags = match_default)
|
Chris@16
|
72 {
|
Chris@16
|
73 return regex_match(str, str + traits::length(str), m, e, flags);
|
Chris@16
|
74 }
|
Chris@16
|
75
|
Chris@16
|
76 template <class ST, class SA, class Allocator, class charT, class traits>
|
Chris@16
|
77 inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
|
Chris@16
|
78 match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
|
Chris@16
|
79 const basic_regex<charT, traits>& e,
|
Chris@16
|
80 match_flag_type flags = match_default)
|
Chris@16
|
81 {
|
Chris@16
|
82 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
83 }
|
Chris@16
|
84 template <class charT, class traits>
|
Chris@16
|
85 inline bool regex_match(const charT* str,
|
Chris@16
|
86 const basic_regex<charT, traits>& e,
|
Chris@16
|
87 match_flag_type flags = match_default)
|
Chris@16
|
88 {
|
Chris@16
|
89 match_results<const charT*> m;
|
Chris@16
|
90 return regex_match(str, str + traits::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
91 }
|
Chris@16
|
92
|
Chris@16
|
93 template <class ST, class SA, class charT, class traits>
|
Chris@16
|
94 inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
|
Chris@16
|
95 const basic_regex<charT, traits>& e,
|
Chris@16
|
96 match_flag_type flags = match_default)
|
Chris@16
|
97 {
|
Chris@16
|
98 typedef typename std::basic_string<charT, ST, SA>::const_iterator iterator;
|
Chris@16
|
99 match_results<iterator> m;
|
Chris@16
|
100 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
101 }
|
Chris@16
|
102 #else // partial ordering
|
Chris@16
|
103 inline bool regex_match(const char* str,
|
Chris@16
|
104 cmatch& m,
|
Chris@16
|
105 const regex& e,
|
Chris@16
|
106 match_flag_type flags = match_default)
|
Chris@16
|
107 {
|
Chris@16
|
108 return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
|
Chris@16
|
109 }
|
Chris@16
|
110 inline bool regex_match(const char* str,
|
Chris@16
|
111 const regex& e,
|
Chris@16
|
112 match_flag_type flags = match_default)
|
Chris@16
|
113 {
|
Chris@16
|
114 match_results<const char*> m;
|
Chris@16
|
115 return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
116 }
|
Chris@16
|
117 #ifndef BOOST_NO_STD_LOCALE
|
Chris@16
|
118 inline bool regex_match(const char* str,
|
Chris@16
|
119 cmatch& m,
|
Chris@16
|
120 const basic_regex<char, cpp_regex_traits<char> >& e,
|
Chris@16
|
121 match_flag_type flags = match_default)
|
Chris@16
|
122 {
|
Chris@16
|
123 return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
|
Chris@16
|
124 }
|
Chris@16
|
125 inline bool regex_match(const char* str,
|
Chris@16
|
126 const basic_regex<char, cpp_regex_traits<char> >& e,
|
Chris@16
|
127 match_flag_type flags = match_default)
|
Chris@16
|
128 {
|
Chris@16
|
129 match_results<const char*> m;
|
Chris@16
|
130 return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
131 }
|
Chris@16
|
132 #endif
|
Chris@16
|
133 inline bool regex_match(const char* str,
|
Chris@16
|
134 cmatch& m,
|
Chris@16
|
135 const basic_regex<char, c_regex_traits<char> >& e,
|
Chris@16
|
136 match_flag_type flags = match_default)
|
Chris@16
|
137 {
|
Chris@16
|
138 return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
|
Chris@16
|
139 }
|
Chris@16
|
140 inline bool regex_match(const char* str,
|
Chris@16
|
141 const basic_regex<char, c_regex_traits<char> >& e,
|
Chris@16
|
142 match_flag_type flags = match_default)
|
Chris@16
|
143 {
|
Chris@16
|
144 match_results<const char*> m;
|
Chris@16
|
145 return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
146 }
|
Chris@16
|
147 #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
|
Chris@16
|
148 inline bool regex_match(const char* str,
|
Chris@16
|
149 cmatch& m,
|
Chris@16
|
150 const basic_regex<char, w32_regex_traits<char> >& e,
|
Chris@16
|
151 match_flag_type flags = match_default)
|
Chris@16
|
152 {
|
Chris@16
|
153 return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
|
Chris@16
|
154 }
|
Chris@16
|
155 inline bool regex_match(const char* str,
|
Chris@16
|
156 const basic_regex<char, w32_regex_traits<char> >& e,
|
Chris@16
|
157 match_flag_type flags = match_default)
|
Chris@16
|
158 {
|
Chris@16
|
159 match_results<const char*> m;
|
Chris@16
|
160 return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
161 }
|
Chris@16
|
162 #endif
|
Chris@16
|
163 #ifndef BOOST_NO_WREGEX
|
Chris@16
|
164 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
165 wcmatch& m,
|
Chris@16
|
166 const wregex& e,
|
Chris@16
|
167 match_flag_type flags = match_default)
|
Chris@16
|
168 {
|
Chris@16
|
169 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
|
Chris@16
|
170 }
|
Chris@16
|
171 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
172 const wregex& e,
|
Chris@16
|
173 match_flag_type flags = match_default)
|
Chris@16
|
174 {
|
Chris@16
|
175 match_results<const wchar_t*> m;
|
Chris@16
|
176 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
177 }
|
Chris@16
|
178 #ifndef BOOST_NO_STD_LOCALE
|
Chris@16
|
179 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
180 wcmatch& m,
|
Chris@16
|
181 const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
|
Chris@16
|
182 match_flag_type flags = match_default)
|
Chris@16
|
183 {
|
Chris@16
|
184 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
|
Chris@16
|
185 }
|
Chris@16
|
186 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
187 const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
|
Chris@16
|
188 match_flag_type flags = match_default)
|
Chris@16
|
189 {
|
Chris@16
|
190 match_results<const wchar_t*> m;
|
Chris@16
|
191 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
192 }
|
Chris@16
|
193 #endif
|
Chris@16
|
194 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
195 wcmatch& m,
|
Chris@16
|
196 const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
|
Chris@16
|
197 match_flag_type flags = match_default)
|
Chris@16
|
198 {
|
Chris@16
|
199 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
|
Chris@16
|
200 }
|
Chris@16
|
201 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
202 const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
|
Chris@16
|
203 match_flag_type flags = match_default)
|
Chris@16
|
204 {
|
Chris@16
|
205 match_results<const wchar_t*> m;
|
Chris@16
|
206 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
207 }
|
Chris@16
|
208 #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
|
Chris@16
|
209 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
210 wcmatch& m,
|
Chris@16
|
211 const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
|
Chris@16
|
212 match_flag_type flags = match_default)
|
Chris@16
|
213 {
|
Chris@16
|
214 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
|
Chris@16
|
215 }
|
Chris@16
|
216 inline bool regex_match(const wchar_t* str,
|
Chris@16
|
217 const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
|
Chris@16
|
218 match_flag_type flags = match_default)
|
Chris@16
|
219 {
|
Chris@16
|
220 match_results<const wchar_t*> m;
|
Chris@16
|
221 return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
|
Chris@16
|
222 }
|
Chris@16
|
223 #endif
|
Chris@16
|
224 #endif
|
Chris@16
|
225 inline bool regex_match(const std::string& s,
|
Chris@16
|
226 smatch& m,
|
Chris@16
|
227 const regex& e,
|
Chris@16
|
228 match_flag_type flags = match_default)
|
Chris@16
|
229 {
|
Chris@16
|
230 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
231 }
|
Chris@16
|
232 inline bool regex_match(const std::string& s,
|
Chris@16
|
233 const regex& e,
|
Chris@16
|
234 match_flag_type flags = match_default)
|
Chris@16
|
235 {
|
Chris@16
|
236 match_results<std::string::const_iterator> m;
|
Chris@16
|
237 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
238 }
|
Chris@16
|
239 #ifndef BOOST_NO_STD_LOCALE
|
Chris@16
|
240 inline bool regex_match(const std::string& s,
|
Chris@16
|
241 smatch& m,
|
Chris@16
|
242 const basic_regex<char, cpp_regex_traits<char> >& e,
|
Chris@16
|
243 match_flag_type flags = match_default)
|
Chris@16
|
244 {
|
Chris@16
|
245 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
246 }
|
Chris@16
|
247 inline bool regex_match(const std::string& s,
|
Chris@16
|
248 const basic_regex<char, cpp_regex_traits<char> >& e,
|
Chris@16
|
249 match_flag_type flags = match_default)
|
Chris@16
|
250 {
|
Chris@16
|
251 match_results<std::string::const_iterator> m;
|
Chris@16
|
252 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
253 }
|
Chris@16
|
254 #endif
|
Chris@16
|
255 inline bool regex_match(const std::string& s,
|
Chris@16
|
256 smatch& m,
|
Chris@16
|
257 const basic_regex<char, c_regex_traits<char> >& e,
|
Chris@16
|
258 match_flag_type flags = match_default)
|
Chris@16
|
259 {
|
Chris@16
|
260 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
261 }
|
Chris@16
|
262 inline bool regex_match(const std::string& s,
|
Chris@16
|
263 const basic_regex<char, c_regex_traits<char> >& e,
|
Chris@16
|
264 match_flag_type flags = match_default)
|
Chris@16
|
265 {
|
Chris@16
|
266 match_results<std::string::const_iterator> m;
|
Chris@16
|
267 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
268 }
|
Chris@16
|
269 #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
|
Chris@16
|
270 inline bool regex_match(const std::string& s,
|
Chris@16
|
271 smatch& m,
|
Chris@16
|
272 const basic_regex<char, w32_regex_traits<char> >& e,
|
Chris@16
|
273 match_flag_type flags = match_default)
|
Chris@16
|
274 {
|
Chris@16
|
275 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
276 }
|
Chris@16
|
277 inline bool regex_match(const std::string& s,
|
Chris@16
|
278 const basic_regex<char, w32_regex_traits<char> >& e,
|
Chris@16
|
279 match_flag_type flags = match_default)
|
Chris@16
|
280 {
|
Chris@16
|
281 match_results<std::string::const_iterator> m;
|
Chris@16
|
282 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
283 }
|
Chris@16
|
284 #endif
|
Chris@16
|
285 #if !defined(BOOST_NO_WREGEX)
|
Chris@16
|
286 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
287 match_results<std::basic_string<wchar_t>::const_iterator>& m,
|
Chris@16
|
288 const wregex& e,
|
Chris@16
|
289 match_flag_type flags = match_default)
|
Chris@16
|
290 {
|
Chris@16
|
291 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
292 }
|
Chris@16
|
293 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
294 const wregex& e,
|
Chris@16
|
295 match_flag_type flags = match_default)
|
Chris@16
|
296 {
|
Chris@16
|
297 match_results<std::basic_string<wchar_t>::const_iterator> m;
|
Chris@16
|
298 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
299 }
|
Chris@16
|
300 #ifndef BOOST_NO_STD_LOCALE
|
Chris@16
|
301 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
302 match_results<std::basic_string<wchar_t>::const_iterator>& m,
|
Chris@16
|
303 const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
|
Chris@16
|
304 match_flag_type flags = match_default)
|
Chris@16
|
305 {
|
Chris@16
|
306 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
307 }
|
Chris@16
|
308 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
309 const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
|
Chris@16
|
310 match_flag_type flags = match_default)
|
Chris@16
|
311 {
|
Chris@16
|
312 match_results<std::basic_string<wchar_t>::const_iterator> m;
|
Chris@16
|
313 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
314 }
|
Chris@16
|
315 #endif
|
Chris@16
|
316 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
317 match_results<std::basic_string<wchar_t>::const_iterator>& m,
|
Chris@16
|
318 const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
|
Chris@16
|
319 match_flag_type flags = match_default)
|
Chris@16
|
320 {
|
Chris@16
|
321 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
322 }
|
Chris@16
|
323 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
324 const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
|
Chris@16
|
325 match_flag_type flags = match_default)
|
Chris@16
|
326 {
|
Chris@16
|
327 match_results<std::basic_string<wchar_t>::const_iterator> m;
|
Chris@16
|
328 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
329 }
|
Chris@16
|
330 #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
|
Chris@16
|
331 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
332 match_results<std::basic_string<wchar_t>::const_iterator>& m,
|
Chris@16
|
333 const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
|
Chris@16
|
334 match_flag_type flags = match_default)
|
Chris@16
|
335 {
|
Chris@16
|
336 return regex_match(s.begin(), s.end(), m, e, flags);
|
Chris@16
|
337 }
|
Chris@16
|
338 inline bool regex_match(const std::basic_string<wchar_t>& s,
|
Chris@16
|
339 const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
|
Chris@16
|
340 match_flag_type flags = match_default)
|
Chris@16
|
341 {
|
Chris@16
|
342 match_results<std::basic_string<wchar_t>::const_iterator> m;
|
Chris@16
|
343 return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
|
Chris@16
|
344 }
|
Chris@16
|
345 #endif
|
Chris@16
|
346 #endif
|
Chris@16
|
347
|
Chris@16
|
348 #endif
|
Chris@16
|
349
|
Chris@16
|
350
|
Chris@16
|
351 #ifdef BOOST_MSVC
|
Chris@16
|
352 #pragma warning(push)
|
Chris@16
|
353 #pragma warning(disable: 4103)
|
Chris@16
|
354 #endif
|
Chris@16
|
355 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
356 # include BOOST_ABI_SUFFIX
|
Chris@16
|
357 #endif
|
Chris@16
|
358 #ifdef BOOST_MSVC
|
Chris@16
|
359 #pragma warning(pop)
|
Chris@16
|
360 #endif
|
Chris@16
|
361
|
Chris@16
|
362 } // namespace boost
|
Chris@16
|
363
|
Chris@16
|
364 #endif // BOOST_REGEX_MATCH_HPP
|
Chris@16
|
365
|
Chris@16
|
366
|
Chris@16
|
367
|
Chris@16
|
368
|
Chris@16
|
369
|
Chris@16
|
370
|
Chris@16
|
371
|
Chris@16
|
372
|
Chris@16
|
373
|
Chris@16
|
374
|
Chris@16
|
375
|
Chris@16
|
376
|
Chris@16
|
377
|
Chris@16
|
378
|
Chris@16
|
379
|
Chris@16
|
380
|
Chris@16
|
381
|
Chris@16
|
382
|