From b8a96d789253c91093476f898611d5903799e84e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 31 Aug 2017 03:43:11 +0300 Subject: Fix regex_replace_ex() to ignore unmatched sub-expression references --- libbutl/regex.txx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libbutl/regex.txx') diff --git a/libbutl/regex.txx b/libbutl/regex.txx index 536cabf..dd1a539 100644 --- a/libbutl/regex.txx +++ b/libbutl/regex.txx @@ -169,9 +169,10 @@ namespace butl if (si > 0) { - // m[0] refers to the matched substring. + // m[0] refers to the matched substring. Note that we + // ignore unmatched sub-expression references. // - if (static_cast (si) < m.size ()) + if (static_cast (si) < m.size () && m[si].matched) append_str (m[si].first, m[si].second); } else @@ -212,9 +213,10 @@ namespace butl int si (digit (c)); if (si > 0) { - // m[0] refers to the matched substring. + // m[0] refers to the matched substring. Note that we + // ignore unmatched sub-expression references. // - if (static_cast (si) < m.size ()) + if (static_cast (si) < m.size () && m[si].matched) append_str (m[si].first, m[si].second); } else -- cgit v1.1