perl_matcher_non_recursive.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,401 行 · 第 1/3 页

HPP
1,401
字号
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_assertion(bool r){   saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);   pstate = pmp->pstate;   position = pmp->position;   bool result = (r == pmp->positive);   m_recursive_result = pmp->positive ? r : !r;   boost::re_detail::inplace_destroy(pmp++);   m_backup_state = pmp;   return !result; // return false if the assertion was matched to stop search.}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_alt(bool r){   saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);   if(!r)   {      pstate = pmp->pstate;      position = pmp->position;   }   boost::re_detail::inplace_destroy(pmp++);   m_backup_state = pmp;   return r; }template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_repeater_counter(bool){   saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);   boost::re_detail::inplace_destroy(pmp++);   m_backup_state = pmp;   return true; // keep looking}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_extra_block(bool){   saved_extra_block* pmp = static_cast<saved_extra_block*>(m_backup_state);   void* condemmed = m_stack_base;   m_stack_base = pmp->base;   m_backup_state = pmp->end;   boost::re_detail::inplace_destroy(pmp);   put_mem_block(condemmed);   return true; // keep looking}template <class BidiIterator, class Allocator, class traits>inline void perl_matcher<BidiIterator, Allocator, traits>::destroy_single_repeat(){   saved_single_repeat<BidiIterator>* p = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);   boost::re_detail::inplace_destroy(p++);   m_backup_state = p;}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_greedy_single_repeat(bool r){   saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);   // if we have a match, just discard this state:   if(r)    {      destroy_single_repeat();      return true;   }   const re_repeat* rep = pmp->rep;   std::size_t count = pmp->count;   BOOST_ASSERT(rep->next.p != 0);   BOOST_ASSERT(rep->alt.p != 0);   count -= rep->min;      if((m_match_flags & match_partial) && (position == last))      m_has_partial_match = true;   BOOST_ASSERT(count);   position = pmp->last_position;   // backtrack till we can skip out:   do   {      --position;      --count;      ++state_count;   }while(count && !can_start(*position, rep->_map, mask_skip));   // if we've hit base, destroy this state:   if(count == 0)   {         destroy_single_repeat();         if(!can_start(*position, rep->_map, mask_skip))            return true;   }   else   {      pmp->count = count + rep->min;      pmp->last_position = position;   }   pstate = rep->alt.p;   return false;}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_slow_dot_repeat(bool r){   saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);   // if we have a match, just discard this state:   if(r)    {      destroy_single_repeat();      return true;   }   const re_repeat* rep = pmp->rep;   std::size_t count = pmp->count;   BOOST_ASSERT(rep->type == syntax_element_dot_rep);   BOOST_ASSERT(rep->next.p != 0);   BOOST_ASSERT(rep->alt.p != 0);   BOOST_ASSERT(rep->next.p->type == syntax_element_wild);   BOOST_ASSERT(count < rep->max);   pstate = rep->next.p;   position = pmp->last_position;   if(position != last)   {      // wind forward until we can skip out of the repeat:      do      {         if(!match_wild())         {            // failed repeat match, discard this state and look for another:            destroy_single_repeat();            return true;         }         ++count;         ++state_count;         pstate = rep->next.p;      }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));   }      if(position == last)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if((m_match_flags & match_partial) && (position == last) && (position != search_base))         m_has_partial_match = true;      if(0 == (rep->can_be_null & mask_skip))         return true;   }   else if(count == rep->max)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if(!can_start(*position, rep->_map, mask_skip))         return true;   }   else   {      pmp->count = count;      pmp->last_position = position;   }   pstate = rep->alt.p;   return false;}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_fast_dot_repeat(bool r){   saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);   // if we have a match, just discard this state:   if(r)    {      destroy_single_repeat();      return true;   }   const re_repeat* rep = pmp->rep;   std::size_t count = pmp->count;   BOOST_ASSERT(count < rep->max);   position = pmp->last_position;   if(position != last)   {      // wind forward until we can skip out of the repeat:      do      {         ++position;         ++count;         ++state_count;      }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));   }   if(position == last)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if((m_match_flags & match_partial) && (position == last) && (position != search_base))         m_has_partial_match = true;      if(0 == (rep->can_be_null & mask_skip))         return true;   }   else if(count == rep->max)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if(!can_start(*position, rep->_map, mask_skip))         return true;   }   else   {      pmp->count = count;      pmp->last_position = position;   }   pstate = rep->alt.p;   return false;}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_char_repeat(bool r){   saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);   // if we have a match, just discard this state:   if(r)    {      destroy_single_repeat();      return true;   }   const re_repeat* rep = pmp->rep;   std::size_t count = pmp->count;   pstate = rep->next.p;   const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(pstate) + 1);   position = pmp->last_position;   BOOST_ASSERT(rep->type == syntax_element_char_rep);   BOOST_ASSERT(rep->next.p != 0);   BOOST_ASSERT(rep->alt.p != 0);   BOOST_ASSERT(rep->next.p->type == syntax_element_literal);   BOOST_ASSERT(count < rep->max);   if(position != last)   {      // wind forward until we can skip out of the repeat:      do      {         if(traits_inst.translate(*position, icase) != what)         {            // failed repeat match, discard this state and look for another:            destroy_single_repeat();            return true;         }         ++count;         ++ position;         ++state_count;         pstate = rep->next.p;      }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));   }      // remember where we got to if this is a leading repeat:   if((rep->leading) && (count < rep->max))      restart = position;   if(position == last)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if((m_match_flags & match_partial) && (position == last) && (position != search_base))         m_has_partial_match = true;      if(0 == (rep->can_be_null & mask_skip))         return true;   }   else if(count == rep->max)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if(!can_start(*position, rep->_map, mask_skip))         return true;   }   else   {      pmp->count = count;      pmp->last_position = position;   }   pstate = rep->alt.p;   return false;}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_short_set_repeat(bool r){   saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);   // if we have a match, just discard this state:   if(r)    {      destroy_single_repeat();      return true;   }   const re_repeat* rep = pmp->rep;   std::size_t count = pmp->count;   pstate = rep->next.p;   const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;   position = pmp->last_position;   BOOST_ASSERT(rep->type == syntax_element_short_set_rep);   BOOST_ASSERT(rep->next.p != 0);   BOOST_ASSERT(rep->alt.p != 0);   BOOST_ASSERT(rep->next.p->type == syntax_element_set);   BOOST_ASSERT(count < rep->max);      if(position != last)   {      // wind forward until we can skip out of the repeat:      do      {         if(!map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])         {            // failed repeat match, discard this state and look for another:            destroy_single_repeat();            return true;         }         ++count;         ++ position;         ++state_count;         pstate = rep->next.p;      }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));   }      // remember where we got to if this is a leading repeat:   if((rep->leading) && (count < rep->max))      restart = position;   if(position == last)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if((m_match_flags & match_partial) && (position == last) && (position != search_base))         m_has_partial_match = true;      if(0 == (rep->can_be_null & mask_skip))         return true;   }   else if(count == rep->max)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if(!can_start(*position, rep->_map, mask_skip))         return true;   }   else   {      pmp->count = count;      pmp->last_position = position;   }   pstate = rep->alt.p;   return false;}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_long_set_repeat(bool r){   typedef typename traits::char_class_type mask_type;   saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);   // if we have a match, just discard this state:   if(r)   {      destroy_single_repeat();      return true;   }   const re_repeat* rep = pmp->rep;   std::size_t count = pmp->count;   pstate = rep->next.p;   const re_set_long<mask_type>* set = static_cast<const re_set_long<mask_type>*>(pstate);   position = pmp->last_position;   BOOST_ASSERT(rep->type == syntax_element_long_set_rep);   BOOST_ASSERT(rep->next.p != 0);   BOOST_ASSERT(rep->alt.p != 0);   BOOST_ASSERT(rep->next.p->type == syntax_element_long_set);   BOOST_ASSERT(count < rep->max);   if(position != last)   {      // wind forward until we can skip out of the repeat:      do      {         if(position == re_is_set_member(position, last, set, re.get_data(), icase))         {            // failed repeat match, discard this state and look for another:            destroy_single_repeat();            return true;         }         ++position;         ++count;         ++state_count;         pstate = rep->next.p;      }while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));   }      // remember where we got to if this is a leading repeat:   if((rep->leading) && (count < rep->max))      restart = position;   if(position == last)   {      // can't repeat any more, remove the pushed state:      destroy_single_repeat();      if((m_match_flags & match_partial) && (position == last) && (position != search_base))         m_has_partial_match = true;      if(0 == (rep->can_be_null & mask_skip))         return true;   }   else if(count == rep->max)   {      // can't repeat any more, remove the pushed state:       destroy_single_repeat();      if(!can_start(*position, rep->_map, mask_skip))         return true;   }   else   {      pmp->count = count;      pmp->last_position = position;   }   pstate = rep->alt.p;   return false;}template <class BidiIterator, class Allocator, class traits>bool perl_matcher<BidiIterator, Allocator, traits>::unwind_non_greedy_repeat(bool r){   saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);   if(!r)   {      position = pmp->position;      pstate = pmp->pstate;      ++(*next_count);   }   boost::re_detail::inplace_destroy(pmp++);   m_backup_state = pmp;   return r;}} // namespace re_detail} // namespace boost#ifdef BOOST_MSVC#  pragma warning(pop)#endif#ifdef BOOST_MSVC#pragma warning(push)#pragma warning(disable: 4103)#endif#ifdef BOOST_HAS_ABI_HEADERS#  include BOOST_ABI_SUFFIX#endif#ifdef BOOST_MSVC#pragma warning(pop)#endif#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?