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)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE perl_matcher_common.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Definitions of perl_matcher member functions that are
17 * specific to the non-recursive implementation.
20 #ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
21 #define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
27 #pragma warning(disable: 4103)
29 #ifdef BOOST_HAS_ABI_HEADERS
30 # include BOOST_ABI_PREFIX
36 # pragma warning(push)
37 # pragma warning(disable: 4800)
44 inline void inplace_destroy(T* p)
46 (void)p; // warning suppression
54 // this padding ensures correct alignment on 64-bit platforms:
56 std::ptrdiff_t padding2;
59 saved_state(unsigned i) : id(i) {}
62 template <class BidiIterator>
63 struct saved_matched_paren : public saved_state
66 sub_match<BidiIterator> sub;
67 saved_matched_paren(int i, const sub_match<BidiIterator>& s) : saved_state(1), index(i), sub(s){};
70 template <class BidiIterator>
71 struct saved_position : public saved_state
73 const re_syntax_base* pstate;
74 BidiIterator position;
75 saved_position(const re_syntax_base* ps, BidiIterator pos, int i) : saved_state(i), pstate(ps), position(pos){};
78 template <class BidiIterator>
79 struct saved_assertion : public saved_position<BidiIterator>
82 saved_assertion(bool p, const re_syntax_base* ps, BidiIterator pos)
83 : saved_position<BidiIterator>(ps, pos, saved_type_assertion), positive(p){};
86 template <class BidiIterator>
87 struct saved_repeater : public saved_state
89 repeater_count<BidiIterator> count;
90 saved_repeater(int i, repeater_count<BidiIterator>** s, BidiIterator start)
91 : saved_state(saved_state_repeater_count), count(i,s,start){}
94 struct saved_extra_block : public saved_state
96 saved_state *base, *end;
97 saved_extra_block(saved_state* b, saved_state* e)
98 : saved_state(saved_state_extra_block), base(b), end(e) {}
101 struct save_state_init
104 save_state_init(saved_state** base, saved_state** end)
107 *base = static_cast<saved_state*>(get_mem_block());
108 *end = reinterpret_cast<saved_state*>(reinterpret_cast<char*>(*base)+BOOST_REGEX_BLOCKSIZE);
110 (void) new (*end)saved_state(0);
111 BOOST_ASSERT(*end > *base);
115 put_mem_block(*stack);
120 template <class BidiIterator>
121 struct saved_single_repeat : public saved_state
124 const re_repeat* rep;
125 BidiIterator last_position;
126 saved_single_repeat(std::size_t c, const re_repeat* r, BidiIterator lp, int arg_id)
127 : saved_state(arg_id), count(c), rep(r), last_position(lp){}
130 template <class BidiIterator, class Allocator, class traits>
131 bool perl_matcher<BidiIterator, Allocator, traits>::match_all_states()
133 static matcher_proc_type const s_match_vtable[29] =
135 (&perl_matcher<BidiIterator, Allocator, traits>::match_startmark),
136 &perl_matcher<BidiIterator, Allocator, traits>::match_endmark,
137 &perl_matcher<BidiIterator, Allocator, traits>::match_literal,
138 &perl_matcher<BidiIterator, Allocator, traits>::match_start_line,
139 &perl_matcher<BidiIterator, Allocator, traits>::match_end_line,
140 &perl_matcher<BidiIterator, Allocator, traits>::match_wild,
141 &perl_matcher<BidiIterator, Allocator, traits>::match_match,
142 &perl_matcher<BidiIterator, Allocator, traits>::match_word_boundary,
143 &perl_matcher<BidiIterator, Allocator, traits>::match_within_word,
144 &perl_matcher<BidiIterator, Allocator, traits>::match_word_start,
145 &perl_matcher<BidiIterator, Allocator, traits>::match_word_end,
146 &perl_matcher<BidiIterator, Allocator, traits>::match_buffer_start,
147 &perl_matcher<BidiIterator, Allocator, traits>::match_buffer_end,
148 &perl_matcher<BidiIterator, Allocator, traits>::match_backref,
149 &perl_matcher<BidiIterator, Allocator, traits>::match_long_set,
150 &perl_matcher<BidiIterator, Allocator, traits>::match_set,
151 &perl_matcher<BidiIterator, Allocator, traits>::match_jump,
152 &perl_matcher<BidiIterator, Allocator, traits>::match_alt,
153 &perl_matcher<BidiIterator, Allocator, traits>::match_rep,
154 &perl_matcher<BidiIterator, Allocator, traits>::match_combining,
155 &perl_matcher<BidiIterator, Allocator, traits>::match_soft_buffer_end,
156 &perl_matcher<BidiIterator, Allocator, traits>::match_restart_continue,
157 (::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow),
158 &perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat,
159 &perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat,
160 &perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat,
161 &perl_matcher<BidiIterator, Allocator, traits>::match_backstep,
162 &perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref,
163 &perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case,
166 push_recursion_stopper();
170 matcher_proc_type proc = s_match_vtable[pstate->type];
174 if(state_count > max_state_count)
175 raise_error(traits_inst, regex_constants::error_space);
176 if((m_match_flags & match_partial) && (position == last) && (position != search_base))
177 m_has_partial_match = true;
178 bool successful_unwind = unwind(false);
179 if((m_match_flags & match_partial) && (position == last) && (position != search_base))
180 m_has_partial_match = true;
181 if(false == successful_unwind)
182 return m_recursive_result;
185 }while(unwind(true));
186 return m_recursive_result;
189 template <class BidiIterator, class Allocator, class traits>
190 void perl_matcher<BidiIterator, Allocator, traits>::extend_stack()
195 saved_state* stack_base;
196 saved_state* backup_state;
197 stack_base = static_cast<saved_state*>(get_mem_block());
198 backup_state = reinterpret_cast<saved_state*>(reinterpret_cast<char*>(stack_base)+BOOST_REGEX_BLOCKSIZE);
199 saved_extra_block* block = static_cast<saved_extra_block*>(backup_state);
201 (void) new (block) saved_extra_block(m_stack_base, m_backup_state);
202 m_stack_base = stack_base;
203 m_backup_state = block;
206 raise_error(traits_inst, regex_constants::error_size);
209 template <class BidiIterator, class Allocator, class traits>
210 inline void perl_matcher<BidiIterator, Allocator, traits>::push_matched_paren(int index, const sub_match<BidiIterator>& sub)
213 saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
215 if(pmp < m_stack_base)
218 pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
221 (void) new (pmp)saved_matched_paren<BidiIterator>(index, sub);
222 m_backup_state = pmp;
225 template <class BidiIterator, class Allocator, class traits>
226 inline void perl_matcher<BidiIterator, Allocator, traits>::push_recursion_stopper()
228 saved_state* pmp = m_backup_state;
230 if(pmp < m_stack_base)
233 pmp = m_backup_state;
236 (void) new (pmp)saved_state(saved_type_recurse);
237 m_backup_state = pmp;
240 template <class BidiIterator, class Allocator, class traits>
241 inline void perl_matcher<BidiIterator, Allocator, traits>::push_assertion(const re_syntax_base* ps, bool positive)
243 saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
245 if(pmp < m_stack_base)
248 pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
251 (void) new (pmp)saved_assertion<BidiIterator>(positive, ps, position);
252 m_backup_state = pmp;
255 template <class BidiIterator, class Allocator, class traits>
256 inline void perl_matcher<BidiIterator, Allocator, traits>::push_alt(const re_syntax_base* ps)
258 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
260 if(pmp < m_stack_base)
263 pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
266 (void) new (pmp)saved_position<BidiIterator>(ps, position, saved_state_alt);
267 m_backup_state = pmp;
270 template <class BidiIterator, class Allocator, class traits>
271 inline void perl_matcher<BidiIterator, Allocator, traits>::push_non_greedy_repeat(const re_syntax_base* ps)
273 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
275 if(pmp < m_stack_base)
278 pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
281 (void) new (pmp)saved_position<BidiIterator>(ps, position, saved_state_non_greedy_long_repeat);
282 m_backup_state = pmp;
285 template <class BidiIterator, class Allocator, class traits>
286 inline void perl_matcher<BidiIterator, Allocator, traits>::push_repeater_count(int i, repeater_count<BidiIterator>** s)
288 saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
290 if(pmp < m_stack_base)
293 pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
296 (void) new (pmp)saved_repeater<BidiIterator>(i, s, position);
297 m_backup_state = pmp;
300 template <class BidiIterator, class Allocator, class traits>
301 inline void perl_matcher<BidiIterator, Allocator, traits>::push_single_repeat(std::size_t c, const re_repeat* r, BidiIterator last_position, int id)
303 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
305 if(pmp < m_stack_base)
308 pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
311 (void) new (pmp)saved_single_repeat<BidiIterator>(c, r, last_position, id);
312 m_backup_state = pmp;
315 template <class BidiIterator, class Allocator, class traits>
316 bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
318 int index = static_cast<const re_brace*>(pstate)->index;
322 pstate = pstate->next.p;
327 // forward lookahead assert:
328 const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
329 pstate = pstate->next.p->next.p;
330 push_assertion(next_pstate, index == -1);
335 // independent sub-expression, currently this is always recursive:
336 bool old_independent = m_independent;
337 m_independent = true;
338 const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
339 pstate = pstate->next.p->next.p;
340 bool r = match_all_states();
341 pstate = next_pstate;
342 m_independent = old_independent;
343 #ifdef BOOST_REGEX_MATCH_EXTRA
344 if(r && (m_match_flags & match_extra))
347 // our captures have been stored in *m_presult
348 // we need to unpack them, and insert them
349 // back in the right order when we unwind the stack:
351 match_results<BidiIterator, Allocator> temp_match(*m_presult);
353 for(i = 0; i < temp_match.size(); ++i)
354 (*m_presult)[i].get_captures().clear();
355 // match everything else:
356 r = match_all_states();
357 // now place the stored captures back:
358 for(i = 0; i < temp_match.size(); ++i)
360 typedef typename sub_match<BidiIterator>::capture_sequence_type seq;
361 seq& s1 = (*m_presult)[i].get_captures();
362 const seq& s2 = temp_match[i].captures();
374 // conditional expression:
375 const re_alt* alt = static_cast<const re_alt*>(pstate->next.p);
376 BOOST_ASSERT(alt->type == syntax_element_alt);
377 pstate = alt->next.p;
378 if(pstate->type == syntax_element_assert_backref)
380 if(!match_assert_backref())
386 // zero width assertion, have to match this recursively:
387 BOOST_ASSERT(pstate->type == syntax_element_startmark);
388 bool negated = static_cast<const re_brace*>(pstate)->index == -2;
389 BidiIterator saved_position = position;
390 const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
391 pstate = pstate->next.p->next.p;
392 bool r = match_all_states();
393 position = saved_position;
397 pstate = next_pstate;
405 BOOST_ASSERT(index > 0);
406 if((m_match_flags & match_nosubs) == 0)
408 push_matched_paren(index, (*m_presult)[index]);
409 m_presult->set_first(position, index);
411 pstate = pstate->next.p;
418 template <class BidiIterator, class Allocator, class traits>
419 bool perl_matcher<BidiIterator, Allocator, traits>::match_alt()
421 bool take_first, take_second;
422 const re_alt* jmp = static_cast<const re_alt*>(pstate);
424 // find out which of these two alternatives we need to take:
427 take_first = jmp->can_be_null & mask_take;
428 take_second = jmp->can_be_null & mask_skip;
432 take_first = can_start(*position, jmp->_map, (unsigned char)mask_take);
433 take_second = can_start(*position, jmp->_map, (unsigned char)mask_skip);
438 // we can take the first alternative,
439 // see if we need to push next alternative:
442 push_alt(jmp->alt.p);
444 pstate = pstate->next.p;
452 return false; // neither option is possible
455 template <class BidiIterator, class Allocator, class traits>
456 bool perl_matcher<BidiIterator, Allocator, traits>::match_rep()
459 #pragma warning(push)
460 #pragma warning(disable:4127 4244)
463 #pragma option push -w-8008 -w-8066 -w-8004
465 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
467 // find out which of these two alternatives we need to take:
468 bool take_first, take_second;
471 take_first = rep->can_be_null & mask_take;
472 take_second = rep->can_be_null & mask_skip;
476 take_first = can_start(*position, rep->_map, (unsigned char)mask_take);
477 take_second = can_start(*position, rep->_map, (unsigned char)mask_skip);
480 if(take_first || (next_count->get_id() != rep->id))
482 // we're moving to a different repeat from the last
483 // one, so set up a counter object:
484 push_repeater_count(rep->id, &next_count);
487 // If we've had at least one repeat already, and the last one
488 // matched the NULL string then set the repeat count to
491 next_count->check_null_repeat(position, rep->max);
493 if(next_count->get_count() < rep->min)
495 // we must take the repeat:
498 // increase the counter:
500 pstate = rep->next.p;
506 bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
509 // try and take the repeat if we can:
510 if((next_count->get_count() < rep->max) && take_first)
514 // store position in case we fail:
515 push_alt(rep->alt.p);
517 // increase the counter:
519 pstate = rep->next.p;
527 return false; // can't take anything, fail...
531 // try and skip the repeat if we can:
534 if((next_count->get_count() < rep->max) && take_first)
536 // store position in case we fail:
537 push_non_greedy_repeat(rep->next.p);
542 if((next_count->get_count() < rep->max) && take_first)
544 // increase the counter:
546 pstate = rep->next.p;
559 template <class BidiIterator, class Allocator, class traits>
560 bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow()
563 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
564 re_syntax_base* psingle = rep->next.p;
565 // match compulsary repeats first:
566 while(count < rep->min)
573 bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
576 // repeat for as long as we can:
577 while(count < rep->max)
584 // remember where we got to if this is a leading repeat:
585 if((rep->leading) && (count < rep->max))
587 // push backtrack info if available:
589 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
590 // jump to next state:
596 // non-greedy, push state and return true if we can skip:
598 push_single_repeat(count, rep, position, saved_state_rep_slow_dot);
600 return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
604 template <class BidiIterator, class Allocator, class traits>
605 bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast()
607 if(m_match_flags & match_not_dot_null)
608 return match_dot_repeat_slow();
609 if((static_cast<const re_dot*>(pstate->next.p)->mask & match_any_mask) == 0)
610 return match_dot_repeat_slow();
612 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
613 bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
614 unsigned count = static_cast<unsigned>((std::min)(static_cast<unsigned>(::boost::re_detail::distance(position, last)), static_cast<unsigned>(greedy ? rep->max : rep->min)));
618 return false; // not enough text left to match
620 std::advance(position, count);
624 if((rep->leading) && (count < rep->max))
626 // push backtrack info if available:
628 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
629 // jump to next state:
635 // non-greedy, push state and return true if we can skip:
637 push_single_repeat(count, rep, position, saved_state_rep_fast_dot);
639 return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
643 template <class BidiIterator, class Allocator, class traits>
644 bool perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat()
647 #pragma warning(push)
648 #pragma warning(disable:4127)
651 #pragma option push -w-8008 -w-8066 -w-8004
653 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
654 BOOST_ASSERT(1 == static_cast<const re_literal*>(rep->next.p)->length);
655 const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(rep->next.p) + 1);
656 std::size_t count = 0;
658 // start by working out how much we can skip:
660 bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
661 std::size_t desired = greedy ? rep->max : rep->min;
662 if(::boost::is_random_access_iterator<BidiIterator>::value)
664 BidiIterator end = position;
665 std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
666 BidiIterator origin(position);
667 while((position != end) && (traits_inst.translate(*position, icase) == what))
671 count = (unsigned)::boost::re_detail::distance(origin, position);
675 while((count < desired) && (position != last) && (traits_inst.translate(*position, icase) == what))
687 if((rep->leading) && (count < rep->max))
689 // push backtrack info if available:
691 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
692 // jump to next state:
698 // non-greedy, push state and return true if we can skip:
700 push_single_repeat(count, rep, position, saved_state_rep_char);
702 return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
712 template <class BidiIterator, class Allocator, class traits>
713 bool perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat()
716 #pragma warning(push)
717 #pragma warning(disable:4127)
720 #pragma option push -w-8008 -w-8066 -w-8004
722 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
723 const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
724 std::size_t count = 0;
726 // start by working out how much we can skip:
728 bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
729 std::size_t desired = greedy ? rep->max : rep->min;
730 if(::boost::is_random_access_iterator<BidiIterator>::value)
732 BidiIterator end = position;
733 std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
734 BidiIterator origin(position);
735 while((position != end) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
739 count = (unsigned)::boost::re_detail::distance(origin, position);
743 while((count < desired) && (position != last) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
755 if((rep->leading) && (count < rep->max))
757 // push backtrack info if available:
759 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
760 // jump to next state:
766 // non-greedy, push state and return true if we can skip:
768 push_single_repeat(count, rep, position, saved_state_rep_short_set);
770 return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
780 template <class BidiIterator, class Allocator, class traits>
781 bool perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat()
784 #pragma warning(push)
785 #pragma warning(disable:4127)
788 #pragma option push -w-8008 -w-8066 -w-8004
790 typedef typename traits::char_class_type mask_type;
791 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
792 const re_set_long<mask_type>* set = static_cast<const re_set_long<mask_type>*>(pstate->next.p);
793 std::size_t count = 0;
795 // start by working out how much we can skip:
797 bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
798 std::size_t desired = greedy ? rep->max : rep->min;
799 if(::boost::is_random_access_iterator<BidiIterator>::value)
801 BidiIterator end = position;
802 std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
803 BidiIterator origin(position);
804 while((position != end) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
808 count = (unsigned)::boost::re_detail::distance(origin, position);
812 while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
824 if((rep->leading) && (count < rep->max))
826 // push backtrack info if available:
828 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
829 // jump to next state:
835 // non-greedy, push state and return true if we can skip:
837 push_single_repeat(count, rep, position, saved_state_rep_long_set);
839 return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
849 /****************************************************************************
851 Unwind and associated proceedures follow, these perform what normal stack
852 unwinding does in the recursive implementation.
854 ****************************************************************************/
856 template <class BidiIterator, class Allocator, class traits>
857 bool perl_matcher<BidiIterator, Allocator, traits>::unwind(bool have_match)
859 static unwind_proc_type const s_unwind_table[14] =
861 &perl_matcher<BidiIterator, Allocator, traits>::unwind_end,
862 &perl_matcher<BidiIterator, Allocator, traits>::unwind_paren,
863 &perl_matcher<BidiIterator, Allocator, traits>::unwind_recursion_stopper,
864 &perl_matcher<BidiIterator, Allocator, traits>::unwind_assertion,
865 &perl_matcher<BidiIterator, Allocator, traits>::unwind_alt,
866 &perl_matcher<BidiIterator, Allocator, traits>::unwind_repeater_counter,
867 &perl_matcher<BidiIterator, Allocator, traits>::unwind_extra_block,
868 &perl_matcher<BidiIterator, Allocator, traits>::unwind_greedy_single_repeat,
869 &perl_matcher<BidiIterator, Allocator, traits>::unwind_slow_dot_repeat,
870 &perl_matcher<BidiIterator, Allocator, traits>::unwind_fast_dot_repeat,
871 &perl_matcher<BidiIterator, Allocator, traits>::unwind_char_repeat,
872 &perl_matcher<BidiIterator, Allocator, traits>::unwind_short_set_repeat,
873 &perl_matcher<BidiIterator, Allocator, traits>::unwind_long_set_repeat,
874 &perl_matcher<BidiIterator, Allocator, traits>::unwind_non_greedy_repeat,
877 m_recursive_result = have_match;
878 unwind_proc_type unwinder;
881 // keep unwinding our stack until we have something to do:
885 unwinder = s_unwind_table[m_backup_state->id];
886 cont = (this->*unwinder)(m_recursive_result);
889 // return true if we have more states to try:
891 return pstate ? true : false;
894 template <class BidiIterator, class Allocator, class traits>
895 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_end(bool)
897 pstate = 0; // nothing left to search
898 return false; // end of stack nothing more to search
901 template <class BidiIterator, class Allocator, class traits>
902 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_paren(bool have_match)
904 saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
905 // restore previous values if no match was found:
906 if(have_match == false)
908 m_presult->set_first(pmp->sub.first, pmp->index);
909 m_presult->set_second(pmp->sub.second, pmp->index, pmp->sub.matched);
911 #ifdef BOOST_REGEX_MATCH_EXTRA
913 // we have a match, push the capture information onto the stack:
915 else if(pmp->sub.matched && (match_extra & m_match_flags))
916 ((*m_presult)[pmp->index]).get_captures().push_back(pmp->sub);
919 m_backup_state = pmp+1;
920 boost::re_detail::inplace_destroy(pmp);
921 return true; // keep looking
924 template <class BidiIterator, class Allocator, class traits>
925 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_recursion_stopper(bool)
927 boost::re_detail::inplace_destroy(m_backup_state++);
928 pstate = 0; // nothing left to search
929 return false; // end of stack nothing more to search
932 template <class BidiIterator, class Allocator, class traits>
933 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_assertion(bool r)
935 saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
936 pstate = pmp->pstate;
937 position = pmp->position;
938 bool result = (r == pmp->positive);
939 m_recursive_result = pmp->positive ? r : !r;
940 boost::re_detail::inplace_destroy(pmp++);
941 m_backup_state = pmp;
942 return !result; // return false if the assertion was matched to stop search.
945 template <class BidiIterator, class Allocator, class traits>
946 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_alt(bool r)
948 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
951 pstate = pmp->pstate;
952 position = pmp->position;
954 boost::re_detail::inplace_destroy(pmp++);
955 m_backup_state = pmp;
959 template <class BidiIterator, class Allocator, class traits>
960 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_repeater_counter(bool)
962 saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
963 boost::re_detail::inplace_destroy(pmp++);
964 m_backup_state = pmp;
965 return true; // keep looking
968 template <class BidiIterator, class Allocator, class traits>
969 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_extra_block(bool)
971 saved_extra_block* pmp = static_cast<saved_extra_block*>(m_backup_state);
972 void* condemmed = m_stack_base;
973 m_stack_base = pmp->base;
974 m_backup_state = pmp->end;
975 boost::re_detail::inplace_destroy(pmp);
976 put_mem_block(condemmed);
977 return true; // keep looking
980 template <class BidiIterator, class Allocator, class traits>
981 inline void perl_matcher<BidiIterator, Allocator, traits>::destroy_single_repeat()
983 saved_single_repeat<BidiIterator>* p = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
984 boost::re_detail::inplace_destroy(p++);
988 template <class BidiIterator, class Allocator, class traits>
989 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_greedy_single_repeat(bool r)
991 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
993 // if we have a match, just discard this state:
996 destroy_single_repeat();
1000 const re_repeat* rep = pmp->rep;
1001 std::size_t count = pmp->count;
1002 BOOST_ASSERT(rep->next.p != 0);
1003 BOOST_ASSERT(rep->alt.p != 0);
1007 if((m_match_flags & match_partial) && (position == last))
1008 m_has_partial_match = true;
1010 BOOST_ASSERT(count);
1011 position = pmp->last_position;
1013 // backtrack till we can skip out:
1019 }while(count && !can_start(*position, rep->_map, mask_skip));
1021 // if we've hit base, destroy this state:
1024 destroy_single_repeat();
1025 if(!can_start(*position, rep->_map, mask_skip))
1030 pmp->count = count + rep->min;
1031 pmp->last_position = position;
1033 pstate = rep->alt.p;
1037 template <class BidiIterator, class Allocator, class traits>
1038 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_slow_dot_repeat(bool r)
1040 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1042 // if we have a match, just discard this state:
1045 destroy_single_repeat();
1049 const re_repeat* rep = pmp->rep;
1050 std::size_t count = pmp->count;
1051 BOOST_ASSERT(rep->type == syntax_element_dot_rep);
1052 BOOST_ASSERT(rep->next.p != 0);
1053 BOOST_ASSERT(rep->alt.p != 0);
1054 BOOST_ASSERT(rep->next.p->type == syntax_element_wild);
1056 BOOST_ASSERT(count < rep->max);
1057 pstate = rep->next.p;
1058 position = pmp->last_position;
1060 if(position != last)
1062 // wind forward until we can skip out of the repeat:
1067 // failed repeat match, discard this state and look for another:
1068 destroy_single_repeat();
1073 pstate = rep->next.p;
1074 }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
1076 if(position == last)
1078 // can't repeat any more, remove the pushed state:
1079 destroy_single_repeat();
1080 if((m_match_flags & match_partial) && (position == last) && (position != search_base))
1081 m_has_partial_match = true;
1082 if(0 == (rep->can_be_null & mask_skip))
1085 else if(count == rep->max)
1087 // can't repeat any more, remove the pushed state:
1088 destroy_single_repeat();
1089 if(!can_start(*position, rep->_map, mask_skip))
1095 pmp->last_position = position;
1097 pstate = rep->alt.p;
1101 template <class BidiIterator, class Allocator, class traits>
1102 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_fast_dot_repeat(bool r)
1104 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1106 // if we have a match, just discard this state:
1109 destroy_single_repeat();
1113 const re_repeat* rep = pmp->rep;
1114 std::size_t count = pmp->count;
1116 BOOST_ASSERT(count < rep->max);
1117 position = pmp->last_position;
1118 if(position != last)
1121 // wind forward until we can skip out of the repeat:
1127 }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
1130 if(position == last)
1132 // can't repeat any more, remove the pushed state:
1133 destroy_single_repeat();
1134 if((m_match_flags & match_partial) && (position == last) && (position != search_base))
1135 m_has_partial_match = true;
1136 if(0 == (rep->can_be_null & mask_skip))
1139 else if(count == rep->max)
1141 // can't repeat any more, remove the pushed state:
1142 destroy_single_repeat();
1143 if(!can_start(*position, rep->_map, mask_skip))
1149 pmp->last_position = position;
1151 pstate = rep->alt.p;
1155 template <class BidiIterator, class Allocator, class traits>
1156 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_char_repeat(bool r)
1158 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1160 // if we have a match, just discard this state:
1163 destroy_single_repeat();
1167 const re_repeat* rep = pmp->rep;
1168 std::size_t count = pmp->count;
1169 pstate = rep->next.p;
1170 const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(pstate) + 1);
1171 position = pmp->last_position;
1173 BOOST_ASSERT(rep->type == syntax_element_char_rep);
1174 BOOST_ASSERT(rep->next.p != 0);
1175 BOOST_ASSERT(rep->alt.p != 0);
1176 BOOST_ASSERT(rep->next.p->type == syntax_element_literal);
1177 BOOST_ASSERT(count < rep->max);
1179 if(position != last)
1181 // wind forward until we can skip out of the repeat:
1184 if(traits_inst.translate(*position, icase) != what)
1186 // failed repeat match, discard this state and look for another:
1187 destroy_single_repeat();
1193 pstate = rep->next.p;
1194 }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
1196 // remember where we got to if this is a leading repeat:
1197 if((rep->leading) && (count < rep->max))
1199 if(position == last)
1201 // can't repeat any more, remove the pushed state:
1202 destroy_single_repeat();
1203 if((m_match_flags & match_partial) && (position == last) && (position != search_base))
1204 m_has_partial_match = true;
1205 if(0 == (rep->can_be_null & mask_skip))
1208 else if(count == rep->max)
1210 // can't repeat any more, remove the pushed state:
1211 destroy_single_repeat();
1212 if(!can_start(*position, rep->_map, mask_skip))
1218 pmp->last_position = position;
1220 pstate = rep->alt.p;
1224 template <class BidiIterator, class Allocator, class traits>
1225 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_short_set_repeat(bool r)
1227 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1229 // if we have a match, just discard this state:
1232 destroy_single_repeat();
1236 const re_repeat* rep = pmp->rep;
1237 std::size_t count = pmp->count;
1238 pstate = rep->next.p;
1239 const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
1240 position = pmp->last_position;
1242 BOOST_ASSERT(rep->type == syntax_element_short_set_rep);
1243 BOOST_ASSERT(rep->next.p != 0);
1244 BOOST_ASSERT(rep->alt.p != 0);
1245 BOOST_ASSERT(rep->next.p->type == syntax_element_set);
1246 BOOST_ASSERT(count < rep->max);
1248 if(position != last)
1250 // wind forward until we can skip out of the repeat:
1253 if(!map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
1255 // failed repeat match, discard this state and look for another:
1256 destroy_single_repeat();
1262 pstate = rep->next.p;
1263 }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
1265 // remember where we got to if this is a leading repeat:
1266 if((rep->leading) && (count < rep->max))
1268 if(position == last)
1270 // can't repeat any more, remove the pushed state:
1271 destroy_single_repeat();
1272 if((m_match_flags & match_partial) && (position == last) && (position != search_base))
1273 m_has_partial_match = true;
1274 if(0 == (rep->can_be_null & mask_skip))
1277 else if(count == rep->max)
1279 // can't repeat any more, remove the pushed state:
1280 destroy_single_repeat();
1281 if(!can_start(*position, rep->_map, mask_skip))
1287 pmp->last_position = position;
1289 pstate = rep->alt.p;
1293 template <class BidiIterator, class Allocator, class traits>
1294 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_long_set_repeat(bool r)
1296 typedef typename traits::char_class_type mask_type;
1297 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1299 // if we have a match, just discard this state:
1302 destroy_single_repeat();
1306 const re_repeat* rep = pmp->rep;
1307 std::size_t count = pmp->count;
1308 pstate = rep->next.p;
1309 const re_set_long<mask_type>* set = static_cast<const re_set_long<mask_type>*>(pstate);
1310 position = pmp->last_position;
1312 BOOST_ASSERT(rep->type == syntax_element_long_set_rep);
1313 BOOST_ASSERT(rep->next.p != 0);
1314 BOOST_ASSERT(rep->alt.p != 0);
1315 BOOST_ASSERT(rep->next.p->type == syntax_element_long_set);
1316 BOOST_ASSERT(count < rep->max);
1318 if(position != last)
1320 // wind forward until we can skip out of the repeat:
1323 if(position == re_is_set_member(position, last, set, re.get_data(), icase))
1325 // failed repeat match, discard this state and look for another:
1326 destroy_single_repeat();
1332 pstate = rep->next.p;
1333 }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
1335 // remember where we got to if this is a leading repeat:
1336 if((rep->leading) && (count < rep->max))
1338 if(position == last)
1340 // can't repeat any more, remove the pushed state:
1341 destroy_single_repeat();
1342 if((m_match_flags & match_partial) && (position == last) && (position != search_base))
1343 m_has_partial_match = true;
1344 if(0 == (rep->can_be_null & mask_skip))
1347 else if(count == rep->max)
1349 // can't repeat any more, remove the pushed state:
1350 destroy_single_repeat();
1351 if(!can_start(*position, rep->_map, mask_skip))
1357 pmp->last_position = position;
1359 pstate = rep->alt.p;
1363 template <class BidiIterator, class Allocator, class traits>
1364 bool perl_matcher<BidiIterator, Allocator, traits>::unwind_non_greedy_repeat(bool r)
1366 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
1369 position = pmp->position;
1370 pstate = pmp->pstate;
1373 boost::re_detail::inplace_destroy(pmp++);
1374 m_backup_state = pmp;
1378 } // namespace re_detail
1379 } // namespace boost
1382 # pragma warning(pop)
1386 #pragma warning(push)
1387 #pragma warning(disable: 4103)
1389 #ifdef BOOST_HAS_ABI_HEADERS
1390 # include BOOST_ABI_SUFFIX
1393 #pragma warning(pop)