Ticket #2269: regex.2.patch

File regex.2.patch, 4.2 KB (added by mickael@…, 14 years ago)

I discovered std::advance

  • basic_regex.hpp

     
    148148   {
    149149      return this->m_mark_count;
    150150   }
     151   std::pair<const_iterator, const_iterator> BOOST_REGEX_CALL get_mark(size_type index)const
     152   {
     153                std::pair<const_iterator, const_iterator> mark(0,0) ;
     154
     155                if(!mark_count() && index < mark_count())
     156                        return mark ;
     157
     158                mark.first = mark.second = this->m_expression ;
     159
     160                if(index == 0)
     161                {
     162                        std::advance(mark.second, this->m_expression_len) ;
     163                        return mark ;
     164                }
     165
     166                ::boost::re_detail::re_syntax_base const *      state = get_first_state() ;
     167                ::boost::re_detail::re_brace const *            state_brace = 0 ;
     168
     169                do
     170                {
     171                        if(state->type != ::boost::re_detail::syntax_element_startmark
     172                                        && state->type != ::boost::re_detail::syntax_element_endmark)
     173                                continue ;
     174
     175                        state_brace = static_cast<re_brace const *>(state) ;
     176                        if(state_brace->index != (int) index)
     177                                continue ;
     178
     179                        if(state_brace->type == ::boost::re_detail::syntax_element_startmark)
     180                                std::advance(mark.first, state_brace->position) ;
     181                        else if(state_brace->type == ::boost::re_detail::syntax_element_endmark)
     182                        {
     183                                std::advance(mark.second, state_brace->position+1) ;
     184                                state = 0 ;
     185                                break ;
     186                        }
     187
     188                } while((state = state->next.p)) ;
     189
     190           return mark ;
     191   }
     192
    151193   const re_detail::re_syntax_base* get_first_state()const
    152194   {
    153195      return this->m_first_state;
     
    405447      return (m_pimpl.get() ? m_pimpl->mark_count() : 0);
    406448   }
    407449
     450   std::pair<const_iterator, const_iterator> BOOST_REGEX_CALL get_mark(size_type index)const
     451   {
     452      return (m_pimpl.get() ? m_pimpl->get_mark(index) : std::pair<const_iterator, const_iterator>(0,0));
     453   }
     454
    408455   int status()const
    409456   {
    410457      return (m_pimpl.get() ? m_pimpl->status() : regex_constants::error_empty);
  • basic_regex_parser.hpp

     
    371371      markid = ++m_mark_count;
    372372   re_brace* pb = static_cast<re_brace*>(this->append_state(syntax_element_startmark, sizeof(re_brace)));
    373373   pb->index = markid;
     374   pb->position = ::boost::re_detail::distance(m_base, m_position - 1) ;
    374375   std::ptrdiff_t last_paren_start = this->getoffset(pb);
    375376   // back up insertion point for alternations, and set new point:
    376377   std::ptrdiff_t last_alt_point = m_alt_insert_point;
     
    421422   //
    422423   pb = static_cast<re_brace*>(this->append_state(syntax_element_endmark, sizeof(re_brace)));
    423424   pb->index = markid;
     425   pb->position = ::boost::re_detail::distance(m_base, m_position-1) ;
    424426   this->m_paren_start = last_paren_start;
    425427   //
    426428   // restore the alternate insertion point:
     
    15491551      m_position = pc;
    15501552      re_brace* pb = static_cast<re_brace*>(this->append_state(syntax_element_backref, sizeof(re_brace)));
    15511553      pb->index = i;
     1554      pb->position = ::boost::re_detail::distance(m_base, m_position) ;
    15521555   }
    15531556   else
    15541557   {
     
    17861789      // make a note of whether we have a case change:
    17871790      m_has_case_change = ((opts & regbase::icase) != (this->flags() & regbase::icase));
    17881791      pb->index = markid = 0;
     1792      pb->position = ::boost::re_detail::distance(m_base, m_position) ;
    17891793      if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_mark)
    17901794      {
    17911795         // update flags and carry on as normal:
     
    18961900   //
    18971901   pb = static_cast<re_brace*>(this->append_state(syntax_element_endmark, sizeof(re_brace)));
    18981902   pb->index = markid;
     1903   pb->position = ::boost::re_detail::distance(m_base, m_position) ;
    18991904   this->m_paren_start = last_paren_start;
    19001905   //
    19011906   // restore the alternate insertion point:
  • states.hpp

     
    156156   // The index to match, can be zero (don't mark the sub-expression)
    157157   // or negative (for perl style (?...) extentions):
    158158   int index;
     159   std::ptrdiff_t position ;
    159160};
    160161
    161162/*** struct re_dot **************************************************