Chris@16
|
1 /*
|
Chris@16
|
2 *
|
Chris@16
|
3 * Copyright (c) 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 #ifndef BOOST_REGEX_MATCHER_HPP
|
Chris@16
|
13 #define BOOST_REGEX_MATCHER_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/regex/v4/iterator_category.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 #ifdef BOOST_MSVC
|
Chris@16
|
18 #pragma warning(push)
|
Chris@16
|
19 #pragma warning(disable: 4103)
|
Chris@16
|
20 #endif
|
Chris@16
|
21 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
22 # include BOOST_ABI_PREFIX
|
Chris@16
|
23 #endif
|
Chris@16
|
24 #ifdef BOOST_MSVC
|
Chris@16
|
25 #pragma warning(pop)
|
Chris@16
|
26 #endif
|
Chris@16
|
27
|
Chris@16
|
28 #ifdef BOOST_MSVC
|
Chris@16
|
29 # pragma warning(push)
|
Chris@16
|
30 # pragma warning(disable: 4800)
|
Chris@16
|
31 #endif
|
Chris@16
|
32
|
Chris@16
|
33 namespace boost{
|
Chris@16
|
34 namespace re_detail{
|
Chris@16
|
35
|
Chris@16
|
36 //
|
Chris@16
|
37 // error checking API:
|
Chris@16
|
38 //
|
Chris@16
|
39 BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type ef, match_flag_type mf);
|
Chris@16
|
40 //
|
Chris@16
|
41 // function can_start:
|
Chris@16
|
42 //
|
Chris@16
|
43 template <class charT>
|
Chris@16
|
44 inline bool can_start(charT c, const unsigned char* map, unsigned char mask)
|
Chris@16
|
45 {
|
Chris@16
|
46 return ((c < static_cast<charT>(0)) ? true : ((c >= static_cast<charT>(1 << CHAR_BIT)) ? true : map[c] & mask));
|
Chris@16
|
47 }
|
Chris@16
|
48 inline bool can_start(char c, const unsigned char* map, unsigned char mask)
|
Chris@16
|
49 {
|
Chris@16
|
50 return map[(unsigned char)c] & mask;
|
Chris@16
|
51 }
|
Chris@16
|
52 inline bool can_start(signed char c, const unsigned char* map, unsigned char mask)
|
Chris@16
|
53 {
|
Chris@16
|
54 return map[(unsigned char)c] & mask;
|
Chris@16
|
55 }
|
Chris@16
|
56 inline bool can_start(unsigned char c, const unsigned char* map, unsigned char mask)
|
Chris@16
|
57 {
|
Chris@16
|
58 return map[c] & mask;
|
Chris@16
|
59 }
|
Chris@16
|
60 inline bool can_start(unsigned short c, const unsigned char* map, unsigned char mask)
|
Chris@16
|
61 {
|
Chris@16
|
62 return ((c >= (1 << CHAR_BIT)) ? true : map[c] & mask);
|
Chris@16
|
63 }
|
Chris@16
|
64 #if !defined(__hpux) && !defined(__WINSCW__)// WCHAR_MIN not usable in pp-directives.
|
Chris@16
|
65 #if defined(WCHAR_MIN) && (WCHAR_MIN == 0) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
Chris@16
|
66 inline bool can_start(wchar_t c, const unsigned char* map, unsigned char mask)
|
Chris@16
|
67 {
|
Chris@16
|
68 return ((c >= static_cast<wchar_t>(1u << CHAR_BIT)) ? true : map[c] & mask);
|
Chris@16
|
69 }
|
Chris@16
|
70 #endif
|
Chris@16
|
71 #endif
|
Chris@16
|
72 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
Chris@16
|
73 inline bool can_start(unsigned int c, const unsigned char* map, unsigned char mask)
|
Chris@16
|
74 {
|
Chris@16
|
75 return (((c >= static_cast<unsigned int>(1u << CHAR_BIT)) ? true : map[c] & mask));
|
Chris@16
|
76 }
|
Chris@16
|
77 #endif
|
Chris@16
|
78
|
Chris@16
|
79
|
Chris@16
|
80 //
|
Chris@16
|
81 // Unfortunately Rogue Waves standard library appears to have a bug
|
Chris@16
|
82 // in std::basic_string::compare that results in eroneous answers
|
Chris@16
|
83 // in some cases (tested with Borland C++ 5.1, Rogue Wave lib version
|
Chris@16
|
84 // 0x020101) the test case was:
|
Chris@16
|
85 // {39135,0} < {0xff,0}
|
Chris@16
|
86 // which succeeds when it should not.
|
Chris@16
|
87 //
|
Chris@16
|
88 #ifndef _RWSTD_VER
|
Chris@16
|
89 template <class C, class T, class A>
|
Chris@16
|
90 inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
|
Chris@16
|
91 {
|
Chris@16
|
92 if(0 == *p)
|
Chris@16
|
93 {
|
Chris@16
|
94 if(s.empty() || ((s.size() == 1) && (s[0] == 0)))
|
Chris@16
|
95 return 0;
|
Chris@16
|
96 }
|
Chris@16
|
97 return s.compare(p);
|
Chris@16
|
98 }
|
Chris@16
|
99 #else
|
Chris@16
|
100 template <class C, class T, class A>
|
Chris@16
|
101 inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
|
Chris@16
|
102 {
|
Chris@16
|
103 if(0 == *p)
|
Chris@16
|
104 {
|
Chris@16
|
105 if(s.empty() || ((s.size() == 1) && (s[0] == 0)))
|
Chris@16
|
106 return 0;
|
Chris@16
|
107 }
|
Chris@16
|
108 return s.compare(p);
|
Chris@16
|
109 }
|
Chris@16
|
110 inline int string_compare(const std::string& s, const char* p)
|
Chris@16
|
111 { return std::strcmp(s.c_str(), p); }
|
Chris@16
|
112 # ifndef BOOST_NO_WREGEX
|
Chris@16
|
113 inline int string_compare(const std::wstring& s, const wchar_t* p)
|
Chris@16
|
114 { return std::wcscmp(s.c_str(), p); }
|
Chris@16
|
115 #endif
|
Chris@16
|
116 #endif
|
Chris@16
|
117 template <class Seq, class C>
|
Chris@16
|
118 inline int string_compare(const Seq& s, const C* p)
|
Chris@16
|
119 {
|
Chris@16
|
120 std::size_t i = 0;
|
Chris@16
|
121 while((i < s.size()) && (p[i] == s[i]))
|
Chris@16
|
122 {
|
Chris@16
|
123 ++i;
|
Chris@16
|
124 }
|
Chris@16
|
125 return (i == s.size()) ? -p[i] : s[i] - p[i];
|
Chris@16
|
126 }
|
Chris@16
|
127 # define STR_COMP(s,p) string_compare(s,p)
|
Chris@16
|
128
|
Chris@16
|
129 template<class charT>
|
Chris@16
|
130 inline const charT* re_skip_past_null(const charT* p)
|
Chris@16
|
131 {
|
Chris@16
|
132 while (*p != static_cast<charT>(0)) ++p;
|
Chris@16
|
133 return ++p;
|
Chris@16
|
134 }
|
Chris@16
|
135
|
Chris@16
|
136 template <class iterator, class charT, class traits_type, class char_classT>
|
Chris@16
|
137 iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
|
Chris@16
|
138 iterator last,
|
Chris@16
|
139 const re_set_long<char_classT>* set_,
|
Chris@16
|
140 const regex_data<charT, traits_type>& e, bool icase)
|
Chris@16
|
141 {
|
Chris@16
|
142 const charT* p = reinterpret_cast<const charT*>(set_+1);
|
Chris@16
|
143 iterator ptr;
|
Chris@16
|
144 unsigned int i;
|
Chris@16
|
145 //bool icase = e.m_flags & regex_constants::icase;
|
Chris@16
|
146
|
Chris@16
|
147 if(next == last) return next;
|
Chris@16
|
148
|
Chris@16
|
149 typedef typename traits_type::string_type traits_string_type;
|
Chris@16
|
150 const ::boost::regex_traits_wrapper<traits_type>& traits_inst = *(e.m_ptraits);
|
Chris@16
|
151
|
Chris@16
|
152 // dwa 9/13/00 suppress incorrect MSVC warning - it claims this is never
|
Chris@16
|
153 // referenced
|
Chris@16
|
154 (void)traits_inst;
|
Chris@16
|
155
|
Chris@16
|
156 // try and match a single character, could be a multi-character
|
Chris@16
|
157 // collating element...
|
Chris@16
|
158 for(i = 0; i < set_->csingles; ++i)
|
Chris@16
|
159 {
|
Chris@16
|
160 ptr = next;
|
Chris@16
|
161 if(*p == static_cast<charT>(0))
|
Chris@16
|
162 {
|
Chris@16
|
163 // treat null string as special case:
|
Chris@16
|
164 if(traits_inst.translate(*ptr, icase) != *p)
|
Chris@16
|
165 {
|
Chris@16
|
166 while(*p == static_cast<charT>(0))++p;
|
Chris@16
|
167 continue;
|
Chris@16
|
168 }
|
Chris@16
|
169 return set_->isnot ? next : (ptr == next) ? ++next : ptr;
|
Chris@16
|
170 }
|
Chris@16
|
171 else
|
Chris@16
|
172 {
|
Chris@16
|
173 while(*p && (ptr != last))
|
Chris@16
|
174 {
|
Chris@16
|
175 if(traits_inst.translate(*ptr, icase) != *p)
|
Chris@16
|
176 break;
|
Chris@16
|
177 ++p;
|
Chris@16
|
178 ++ptr;
|
Chris@16
|
179 }
|
Chris@16
|
180
|
Chris@16
|
181 if(*p == static_cast<charT>(0)) // if null we've matched
|
Chris@16
|
182 return set_->isnot ? next : (ptr == next) ? ++next : ptr;
|
Chris@16
|
183
|
Chris@16
|
184 p = re_skip_past_null(p); // skip null
|
Chris@16
|
185 }
|
Chris@16
|
186 }
|
Chris@16
|
187
|
Chris@16
|
188 charT col = traits_inst.translate(*next, icase);
|
Chris@16
|
189
|
Chris@16
|
190
|
Chris@16
|
191 if(set_->cranges || set_->cequivalents)
|
Chris@16
|
192 {
|
Chris@16
|
193 traits_string_type s1;
|
Chris@16
|
194 //
|
Chris@16
|
195 // try and match a range, NB only a single character can match
|
Chris@16
|
196 if(set_->cranges)
|
Chris@16
|
197 {
|
Chris@16
|
198 if((e.m_flags & regex_constants::collate) == 0)
|
Chris@16
|
199 s1.assign(1, col);
|
Chris@16
|
200 else
|
Chris@16
|
201 {
|
Chris@16
|
202 charT a[2] = { col, charT(0), };
|
Chris@16
|
203 s1 = traits_inst.transform(a, a + 1);
|
Chris@16
|
204 }
|
Chris@16
|
205 for(i = 0; i < set_->cranges; ++i)
|
Chris@16
|
206 {
|
Chris@16
|
207 if(STR_COMP(s1, p) >= 0)
|
Chris@16
|
208 {
|
Chris@16
|
209 do{ ++p; }while(*p);
|
Chris@16
|
210 ++p;
|
Chris@16
|
211 if(STR_COMP(s1, p) <= 0)
|
Chris@16
|
212 return set_->isnot ? next : ++next;
|
Chris@16
|
213 }
|
Chris@16
|
214 else
|
Chris@16
|
215 {
|
Chris@16
|
216 // skip first string
|
Chris@16
|
217 do{ ++p; }while(*p);
|
Chris@16
|
218 ++p;
|
Chris@16
|
219 }
|
Chris@16
|
220 // skip second string
|
Chris@16
|
221 do{ ++p; }while(*p);
|
Chris@16
|
222 ++p;
|
Chris@16
|
223 }
|
Chris@16
|
224 }
|
Chris@16
|
225 //
|
Chris@16
|
226 // try and match an equivalence class, NB only a single character can match
|
Chris@16
|
227 if(set_->cequivalents)
|
Chris@16
|
228 {
|
Chris@16
|
229 charT a[2] = { col, charT(0), };
|
Chris@16
|
230 s1 = traits_inst.transform_primary(a, a +1);
|
Chris@16
|
231 for(i = 0; i < set_->cequivalents; ++i)
|
Chris@16
|
232 {
|
Chris@16
|
233 if(STR_COMP(s1, p) == 0)
|
Chris@16
|
234 return set_->isnot ? next : ++next;
|
Chris@16
|
235 // skip string
|
Chris@16
|
236 do{ ++p; }while(*p);
|
Chris@16
|
237 ++p;
|
Chris@16
|
238 }
|
Chris@16
|
239 }
|
Chris@16
|
240 }
|
Chris@16
|
241 if(traits_inst.isctype(col, set_->cclasses) == true)
|
Chris@16
|
242 return set_->isnot ? next : ++next;
|
Chris@16
|
243 if((set_->cnclasses != 0) && (traits_inst.isctype(col, set_->cnclasses) == false))
|
Chris@16
|
244 return set_->isnot ? next : ++next;
|
Chris@16
|
245 return set_->isnot ? ++next : next;
|
Chris@16
|
246 }
|
Chris@16
|
247
|
Chris@16
|
248 template <class BidiIterator>
|
Chris@16
|
249 class repeater_count
|
Chris@16
|
250 {
|
Chris@16
|
251 repeater_count** stack;
|
Chris@16
|
252 repeater_count* next;
|
Chris@16
|
253 int state_id;
|
Chris@16
|
254 std::size_t count; // the number of iterations so far
|
Chris@16
|
255 BidiIterator start_pos; // where the last repeat started
|
Chris@16
|
256 public:
|
Chris@101
|
257 repeater_count(repeater_count** s) : stack(s), next(0), state_id(-1), count(0), start_pos() {}
|
Chris@101
|
258
|
Chris@16
|
259 repeater_count(int i, repeater_count** s, BidiIterator start)
|
Chris@16
|
260 : start_pos(start)
|
Chris@16
|
261 {
|
Chris@16
|
262 state_id = i;
|
Chris@16
|
263 stack = s;
|
Chris@16
|
264 next = *stack;
|
Chris@16
|
265 *stack = this;
|
Chris@16
|
266 if(state_id > next->state_id)
|
Chris@16
|
267 count = 0;
|
Chris@16
|
268 else
|
Chris@16
|
269 {
|
Chris@16
|
270 repeater_count* p = next;
|
Chris@16
|
271 while(p && (p->state_id != state_id))
|
Chris@16
|
272 p = p->next;
|
Chris@16
|
273 if(p)
|
Chris@16
|
274 {
|
Chris@16
|
275 count = p->count;
|
Chris@16
|
276 start_pos = p->start_pos;
|
Chris@16
|
277 }
|
Chris@16
|
278 else
|
Chris@16
|
279 count = 0;
|
Chris@16
|
280 }
|
Chris@16
|
281 }
|
Chris@16
|
282 ~repeater_count()
|
Chris@16
|
283 {
|
Chris@16
|
284 if(next)
|
Chris@16
|
285 *stack = next;
|
Chris@16
|
286 }
|
Chris@16
|
287 std::size_t get_count() { return count; }
|
Chris@16
|
288 int get_id() { return state_id; }
|
Chris@16
|
289 std::size_t operator++() { return ++count; }
|
Chris@16
|
290 bool check_null_repeat(const BidiIterator& pos, std::size_t max)
|
Chris@16
|
291 {
|
Chris@16
|
292 // this is called when we are about to start a new repeat,
|
Chris@16
|
293 // if the last one was NULL move our count to max,
|
Chris@16
|
294 // otherwise save the current position.
|
Chris@16
|
295 bool result = (count == 0) ? false : (pos == start_pos);
|
Chris@16
|
296 if(result)
|
Chris@16
|
297 count = max;
|
Chris@16
|
298 else
|
Chris@16
|
299 start_pos = pos;
|
Chris@16
|
300 return result;
|
Chris@16
|
301 }
|
Chris@16
|
302 };
|
Chris@16
|
303
|
Chris@16
|
304 struct saved_state;
|
Chris@16
|
305
|
Chris@16
|
306 enum saved_state_type
|
Chris@16
|
307 {
|
Chris@16
|
308 saved_type_end = 0,
|
Chris@16
|
309 saved_type_paren = 1,
|
Chris@16
|
310 saved_type_recurse = 2,
|
Chris@16
|
311 saved_type_assertion = 3,
|
Chris@16
|
312 saved_state_alt = 4,
|
Chris@16
|
313 saved_state_repeater_count = 5,
|
Chris@16
|
314 saved_state_extra_block = 6,
|
Chris@16
|
315 saved_state_greedy_single_repeat = 7,
|
Chris@16
|
316 saved_state_rep_slow_dot = 8,
|
Chris@16
|
317 saved_state_rep_fast_dot = 9,
|
Chris@16
|
318 saved_state_rep_char = 10,
|
Chris@16
|
319 saved_state_rep_short_set = 11,
|
Chris@16
|
320 saved_state_rep_long_set = 12,
|
Chris@16
|
321 saved_state_non_greedy_long_repeat = 13,
|
Chris@16
|
322 saved_state_count = 14
|
Chris@16
|
323 };
|
Chris@16
|
324
|
Chris@16
|
325 template <class Results>
|
Chris@16
|
326 struct recursion_info
|
Chris@16
|
327 {
|
Chris@16
|
328 typedef typename Results::value_type value_type;
|
Chris@16
|
329 typedef typename value_type::iterator iterator;
|
Chris@16
|
330 int idx;
|
Chris@16
|
331 const re_syntax_base* preturn_address;
|
Chris@16
|
332 Results results;
|
Chris@16
|
333 repeater_count<iterator>* repeater_stack;
|
Chris@16
|
334 };
|
Chris@16
|
335
|
Chris@16
|
336 #ifdef BOOST_MSVC
|
Chris@16
|
337 #pragma warning(push)
|
Chris@16
|
338 #pragma warning(disable : 4251 4231)
|
Chris@16
|
339 # if BOOST_MSVC < 1600
|
Chris@16
|
340 # pragma warning(disable : 4660)
|
Chris@16
|
341 # endif
|
Chris@16
|
342 #endif
|
Chris@16
|
343
|
Chris@16
|
344 template <class BidiIterator, class Allocator, class traits>
|
Chris@16
|
345 class perl_matcher
|
Chris@16
|
346 {
|
Chris@16
|
347 public:
|
Chris@16
|
348 typedef typename traits::char_type char_type;
|
Chris@16
|
349 typedef perl_matcher<BidiIterator, Allocator, traits> self_type;
|
Chris@16
|
350 typedef bool (self_type::*matcher_proc_type)(void);
|
Chris@16
|
351 typedef std::size_t traits_size_type;
|
Chris@16
|
352 typedef typename is_byte<char_type>::width_type width_type;
|
Chris@16
|
353 typedef typename regex_iterator_traits<BidiIterator>::difference_type difference_type;
|
Chris@16
|
354 typedef match_results<BidiIterator, Allocator> results_type;
|
Chris@16
|
355
|
Chris@16
|
356 perl_matcher(BidiIterator first, BidiIterator end,
|
Chris@16
|
357 match_results<BidiIterator, Allocator>& what,
|
Chris@16
|
358 const basic_regex<char_type, traits>& e,
|
Chris@16
|
359 match_flag_type f,
|
Chris@16
|
360 BidiIterator l_base)
|
Chris@16
|
361 : m_result(what), base(first), last(end),
|
Chris@16
|
362 position(first), backstop(l_base), re(e), traits_inst(e.get_traits()),
|
Chris@16
|
363 m_independent(false), next_count(&rep_obj), rep_obj(&next_count)
|
Chris@16
|
364 {
|
Chris@16
|
365 construct_init(e, f);
|
Chris@16
|
366 }
|
Chris@16
|
367
|
Chris@16
|
368 bool match();
|
Chris@16
|
369 bool find();
|
Chris@16
|
370
|
Chris@16
|
371 void setf(match_flag_type f)
|
Chris@16
|
372 { m_match_flags |= f; }
|
Chris@16
|
373 void unsetf(match_flag_type f)
|
Chris@16
|
374 { m_match_flags &= ~f; }
|
Chris@16
|
375
|
Chris@16
|
376 private:
|
Chris@16
|
377 void construct_init(const basic_regex<char_type, traits>& e, match_flag_type f);
|
Chris@16
|
378
|
Chris@16
|
379 bool find_imp();
|
Chris@16
|
380 bool match_imp();
|
Chris@16
|
381 #ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
|
Chris@16
|
382 typedef bool (perl_matcher::*protected_proc_type)();
|
Chris@16
|
383 bool protected_call(protected_proc_type);
|
Chris@16
|
384 #endif
|
Chris@16
|
385 void estimate_max_state_count(std::random_access_iterator_tag*);
|
Chris@16
|
386 void estimate_max_state_count(void*);
|
Chris@16
|
387 bool match_prefix();
|
Chris@16
|
388 bool match_all_states();
|
Chris@16
|
389
|
Chris@16
|
390 // match procs, stored in s_match_vtable:
|
Chris@16
|
391 bool match_startmark();
|
Chris@16
|
392 bool match_endmark();
|
Chris@16
|
393 bool match_literal();
|
Chris@16
|
394 bool match_start_line();
|
Chris@16
|
395 bool match_end_line();
|
Chris@16
|
396 bool match_wild();
|
Chris@16
|
397 bool match_match();
|
Chris@16
|
398 bool match_word_boundary();
|
Chris@16
|
399 bool match_within_word();
|
Chris@16
|
400 bool match_word_start();
|
Chris@16
|
401 bool match_word_end();
|
Chris@16
|
402 bool match_buffer_start();
|
Chris@16
|
403 bool match_buffer_end();
|
Chris@16
|
404 bool match_backref();
|
Chris@16
|
405 bool match_long_set();
|
Chris@16
|
406 bool match_set();
|
Chris@16
|
407 bool match_jump();
|
Chris@16
|
408 bool match_alt();
|
Chris@16
|
409 bool match_rep();
|
Chris@16
|
410 bool match_combining();
|
Chris@16
|
411 bool match_soft_buffer_end();
|
Chris@16
|
412 bool match_restart_continue();
|
Chris@16
|
413 bool match_long_set_repeat();
|
Chris@16
|
414 bool match_set_repeat();
|
Chris@16
|
415 bool match_char_repeat();
|
Chris@16
|
416 bool match_dot_repeat_fast();
|
Chris@16
|
417 bool match_dot_repeat_slow();
|
Chris@16
|
418 bool match_dot_repeat_dispatch()
|
Chris@16
|
419 {
|
Chris@16
|
420 return ::boost::is_random_access_iterator<BidiIterator>::value ? match_dot_repeat_fast() : match_dot_repeat_slow();
|
Chris@16
|
421 }
|
Chris@16
|
422 bool match_backstep();
|
Chris@16
|
423 bool match_assert_backref();
|
Chris@16
|
424 bool match_toggle_case();
|
Chris@16
|
425 #ifdef BOOST_REGEX_RECURSIVE
|
Chris@16
|
426 bool backtrack_till_match(std::size_t count);
|
Chris@16
|
427 #endif
|
Chris@16
|
428 bool match_recursion();
|
Chris@16
|
429
|
Chris@16
|
430 // find procs stored in s_find_vtable:
|
Chris@16
|
431 bool find_restart_any();
|
Chris@16
|
432 bool find_restart_word();
|
Chris@16
|
433 bool find_restart_line();
|
Chris@16
|
434 bool find_restart_buf();
|
Chris@16
|
435 bool find_restart_lit();
|
Chris@16
|
436
|
Chris@16
|
437 private:
|
Chris@16
|
438 // final result structure to be filled in:
|
Chris@16
|
439 match_results<BidiIterator, Allocator>& m_result;
|
Chris@16
|
440 // temporary result for POSIX matches:
|
Chris@16
|
441 scoped_ptr<match_results<BidiIterator, Allocator> > m_temp_match;
|
Chris@16
|
442 // pointer to actual result structure to fill in:
|
Chris@16
|
443 match_results<BidiIterator, Allocator>* m_presult;
|
Chris@16
|
444 // start of sequence being searched:
|
Chris@16
|
445 BidiIterator base;
|
Chris@16
|
446 // end of sequence being searched:
|
Chris@16
|
447 BidiIterator last;
|
Chris@16
|
448 // current character being examined:
|
Chris@16
|
449 BidiIterator position;
|
Chris@16
|
450 // where to restart next search after failed match attempt:
|
Chris@16
|
451 BidiIterator restart;
|
Chris@16
|
452 // where the current search started from, acts as base for $` during grep:
|
Chris@16
|
453 BidiIterator search_base;
|
Chris@16
|
454 // how far we can go back when matching lookbehind:
|
Chris@16
|
455 BidiIterator backstop;
|
Chris@16
|
456 // the expression being examined:
|
Chris@16
|
457 const basic_regex<char_type, traits>& re;
|
Chris@16
|
458 // the expression's traits class:
|
Chris@16
|
459 const ::boost::regex_traits_wrapper<traits>& traits_inst;
|
Chris@16
|
460 // the next state in the machine being matched:
|
Chris@16
|
461 const re_syntax_base* pstate;
|
Chris@16
|
462 // matching flags in use:
|
Chris@16
|
463 match_flag_type m_match_flags;
|
Chris@16
|
464 // how many states we have examined so far:
|
Chris@16
|
465 std::ptrdiff_t state_count;
|
Chris@16
|
466 // max number of states to examine before giving up:
|
Chris@16
|
467 std::ptrdiff_t max_state_count;
|
Chris@16
|
468 // whether we should ignore case or not:
|
Chris@16
|
469 bool icase;
|
Chris@16
|
470 // set to true when (position == last), indicates that we may have a partial match:
|
Chris@16
|
471 bool m_has_partial_match;
|
Chris@16
|
472 // set to true whenever we get a match:
|
Chris@16
|
473 bool m_has_found_match;
|
Chris@16
|
474 // set to true whenever we're inside an independent sub-expression:
|
Chris@16
|
475 bool m_independent;
|
Chris@16
|
476 // the current repeat being examined:
|
Chris@16
|
477 repeater_count<BidiIterator>* next_count;
|
Chris@16
|
478 // the first repeat being examined (top of linked list):
|
Chris@16
|
479 repeater_count<BidiIterator> rep_obj;
|
Chris@16
|
480 // the mask to pass when matching word boundaries:
|
Chris@16
|
481 typename traits::char_class_type m_word_mask;
|
Chris@16
|
482 // the bitmask to use when determining whether a match_any matches a newline or not:
|
Chris@16
|
483 unsigned char match_any_mask;
|
Chris@16
|
484 // recursion information:
|
Chris@16
|
485 std::vector<recursion_info<results_type> > recursion_stack;
|
Chris@16
|
486
|
Chris@16
|
487 #ifdef BOOST_REGEX_NON_RECURSIVE
|
Chris@16
|
488 //
|
Chris@16
|
489 // additional members for non-recursive version:
|
Chris@16
|
490 //
|
Chris@16
|
491 typedef bool (self_type::*unwind_proc_type)(bool);
|
Chris@16
|
492
|
Chris@16
|
493 void extend_stack();
|
Chris@16
|
494 bool unwind(bool);
|
Chris@16
|
495 bool unwind_end(bool);
|
Chris@16
|
496 bool unwind_paren(bool);
|
Chris@16
|
497 bool unwind_recursion_stopper(bool);
|
Chris@16
|
498 bool unwind_assertion(bool);
|
Chris@16
|
499 bool unwind_alt(bool);
|
Chris@16
|
500 bool unwind_repeater_counter(bool);
|
Chris@16
|
501 bool unwind_extra_block(bool);
|
Chris@16
|
502 bool unwind_greedy_single_repeat(bool);
|
Chris@16
|
503 bool unwind_slow_dot_repeat(bool);
|
Chris@16
|
504 bool unwind_fast_dot_repeat(bool);
|
Chris@16
|
505 bool unwind_char_repeat(bool);
|
Chris@16
|
506 bool unwind_short_set_repeat(bool);
|
Chris@16
|
507 bool unwind_long_set_repeat(bool);
|
Chris@16
|
508 bool unwind_non_greedy_repeat(bool);
|
Chris@16
|
509 bool unwind_recursion(bool);
|
Chris@16
|
510 bool unwind_recursion_pop(bool);
|
Chris@16
|
511 void destroy_single_repeat();
|
Chris@16
|
512 void push_matched_paren(int index, const sub_match<BidiIterator>& sub);
|
Chris@16
|
513 void push_recursion_stopper();
|
Chris@16
|
514 void push_assertion(const re_syntax_base* ps, bool positive);
|
Chris@16
|
515 void push_alt(const re_syntax_base* ps);
|
Chris@16
|
516 void push_repeater_count(int i, repeater_count<BidiIterator>** s);
|
Chris@16
|
517 void push_single_repeat(std::size_t c, const re_repeat* r, BidiIterator last_position, int state_id);
|
Chris@16
|
518 void push_non_greedy_repeat(const re_syntax_base* ps);
|
Chris@16
|
519 void push_recursion(int idx, const re_syntax_base* p, results_type* presults);
|
Chris@16
|
520 void push_recursion_pop();
|
Chris@16
|
521
|
Chris@16
|
522 // pointer to base of stack:
|
Chris@16
|
523 saved_state* m_stack_base;
|
Chris@16
|
524 // pointer to current stack position:
|
Chris@16
|
525 saved_state* m_backup_state;
|
Chris@16
|
526 // determines what value to return when unwinding from recursion,
|
Chris@16
|
527 // allows for mixed recursive/non-recursive algorithm:
|
Chris@16
|
528 bool m_recursive_result;
|
Chris@16
|
529 // how many memory blocks have we used up?:
|
Chris@16
|
530 unsigned used_block_count;
|
Chris@16
|
531 #endif
|
Chris@16
|
532
|
Chris@16
|
533 // these operations aren't allowed, so are declared private,
|
Chris@16
|
534 // bodies are provided to keep explicit-instantiation requests happy:
|
Chris@16
|
535 perl_matcher& operator=(const perl_matcher&)
|
Chris@16
|
536 {
|
Chris@16
|
537 return *this;
|
Chris@16
|
538 }
|
Chris@16
|
539 perl_matcher(const perl_matcher& that)
|
Chris@16
|
540 : m_result(that.m_result), re(that.re), traits_inst(that.traits_inst), rep_obj(0) {}
|
Chris@16
|
541 };
|
Chris@16
|
542
|
Chris@16
|
543 #ifdef BOOST_MSVC
|
Chris@16
|
544 #pragma warning(pop)
|
Chris@16
|
545 #endif
|
Chris@16
|
546
|
Chris@16
|
547 } // namespace re_detail
|
Chris@16
|
548
|
Chris@16
|
549 #ifdef BOOST_MSVC
|
Chris@16
|
550 #pragma warning(push)
|
Chris@16
|
551 #pragma warning(disable: 4103)
|
Chris@16
|
552 #endif
|
Chris@16
|
553 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
554 # include BOOST_ABI_SUFFIX
|
Chris@16
|
555 #endif
|
Chris@16
|
556 #ifdef BOOST_MSVC
|
Chris@16
|
557 #pragma warning(pop)
|
Chris@16
|
558 #endif
|
Chris@16
|
559
|
Chris@16
|
560 } // namespace boost
|
Chris@16
|
561
|
Chris@16
|
562 #ifdef BOOST_MSVC
|
Chris@16
|
563 # pragma warning(pop)
|
Chris@16
|
564 #endif
|
Chris@16
|
565
|
Chris@16
|
566 //
|
Chris@16
|
567 // include the implementation of perl_matcher:
|
Chris@16
|
568 //
|
Chris@16
|
569 #ifdef BOOST_REGEX_RECURSIVE
|
Chris@16
|
570 #include <boost/regex/v4/perl_matcher_recursive.hpp>
|
Chris@16
|
571 #else
|
Chris@16
|
572 #include <boost/regex/v4/perl_matcher_non_recursive.hpp>
|
Chris@16
|
573 #endif
|
Chris@16
|
574 // this one has to be last:
|
Chris@16
|
575 #include <boost/regex/v4/perl_matcher_common.hpp>
|
Chris@16
|
576
|
Chris@16
|
577 #endif
|
Chris@16
|
578
|