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