Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions include/boost/regex/v5/match_results.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,23 @@ class match_results
bool empty() const
{ return m_subs.size() < 2; }
// element access:
difference_type length(int sub = 0) const
private:
difference_type do_get_length(int sub = 0) const
{
if(m_is_singular)
if (m_is_singular)
raise_logic_error();
sub += 2;
if((sub < (int)m_subs.size()) && (sub > 0))
if ((sub < (int)m_subs.size()) && (sub > 0))
return m_subs[sub].length();
return 0;
}
public:
template <class Integer>
typename std::enable_if<std::is_integral<Integer>::value, difference_type>::type length(Integer sub) const
{
return do_get_length(static_cast<int>(sub));
}
difference_type length() const { return do_get_length(0); }
difference_type length(const char_type* sub) const
{
if(m_is_singular)
Expand Down Expand Up @@ -161,7 +169,8 @@ class match_results
{
return position(sub.c_str());
}
string_type str(int sub = 0) const
private:
string_type do_get_string(int sub = 0) const
{
if(m_is_singular)
raise_logic_error();
Expand All @@ -177,6 +186,13 @@ class match_results
}
return result;
}
public:
template <class Integer>
typename std::enable_if<std::is_integral<Integer>::value, string_type>::type str(Integer sub) const
{
return do_get_string(static_cast<int>(sub));
}
string_type str() const { return do_get_string(0); }
string_type str(const char_type* sub) const
{
return (*this)[sub].str();
Expand All @@ -196,7 +212,8 @@ class match_results
{
return (*this)[sub].str();
}
const_reference operator[](int sub) const
private:
const_reference get_at(int sub) const
{
if(m_is_singular && m_subs.empty())
raise_logic_error();
Expand All @@ -207,6 +224,12 @@ class match_results
}
return m_null;
}
public:
template <class Integer>
typename std::enable_if<std::is_integral<Integer>::value, const_reference>::type operator[](Integer sub) const
{
return get_at(static_cast<int>(sub));
}
//
// Named sub-expressions:
//
Expand Down