The first two elements in the m_subs
vector property of the boost::match_results
class defined in match_results.hpp
are reserved for storing the prefix and suffix. Their exact meanings are:
m_subs[0] - suffix
m_subs[0].first - the end position of the match
m_subs[0].second - the end position of the input text
m_subs[0].matched - m_subs[0].first != m_subs[0].second
m_subs[1] - prefix
m_subs[1].first - the start position of the input text
m_subs[1].second - the start position of the match
m_subs[1].matched - m_subs[1].first != m_subs[1].second
The match positions of capture group $0 are stored in m_subs[2], $1 in m_subs[3], etc, which can be referenced through the match_results class via [0], [1], etc. That is why you can see the magic number 2 added in several places.
Have a look at how match_results' suffix
and prefix
methods are implemented:
const_reference prefix() const
{
if(m_is_singular)
raise_logic_error();
return (*this)[-1];
}
const_reference suffix() const
{
if(m_is_singular)
raise_logic_error();
return (*this)[-2];
}
Since this has been so for quite a while I would not be quick to assume this is causing your particular problem. If you need more help please ask another question containing a SSCCE outlining your problem.
P.S. you're not insane (the above is just really terrible code)