Ticket #2269: regex.patch

File regex.patch, 4.3 KB (added by mickael@…, 14 years ago)
  • 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                ptrdiff_t position = this->m_expression_len ;
     155
     156                if(!mark_count() && index < mark_count())
     157                        return mark ;
     158
     159                mark.first = mark.second = this->m_expression ;
     160
     161                if(index == 0)
     162                {
     163                        while(position--) mark.second++ ; // We seek after the last
     164                        return mark ;
     165                }
     166
     167                ::boost::re_detail::re_syntax_base const *      state = get_first_state() ;
     168                ::boost::re_detail::re_brace const *            state_brace = 0 ;
     169
     170                do
     171                {
     172                        if(state->type != ::boost::re_detail::syntax_element_startmark
     173                                        && state->type != ::boost::re_detail::syntax_element_endmark)
     174                                continue ;
     175
     176                        state_brace = static_cast<re_brace const *>(state) ;
     177                        if(state_brace->index != (int) index)
     178                                continue ;
     179
     180                        ptrdiff_t position = state_brace->position ;
     181                        if(state_brace->type == ::boost::re_detail::syntax_element_startmark)
     182                                while(--position) mark.first++ ; // We seek on '('
     183                        else if(state_brace->type == ::boost::re_detail::syntax_element_endmark)
     184                        {
     185                                while(position--) mark.second++ ; // We seek after ')'
     186                                state = 0 ;
     187                                break ;
     188                        }
     189
     190                } while((state = state->next.p)) ;
     191
     192           return mark ;
     193   }
     194
    151195   const re_detail::re_syntax_base* get_first_state()const
    152196   {
    153197      return this->m_first_state;
     
    405449      return (m_pimpl.get() ? m_pimpl->mark_count() : 0);
    406450   }
    407451
     452   std::pair<const_iterator, const_iterator> BOOST_REGEX_CALL get_mark(size_type index)const
     453   {
     454      return (m_pimpl.get() ? m_pimpl->get_mark(index) : std::pair<const_iterator, const_iterator>(0,0));
     455   }
     456
    408457   int status()const
    409458   {
    410459      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) ;
    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) ;
    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 **************************************************