aboutsummaryrefslogtreecommitdiff
path: root/libbutl/regex.txx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-08-31 03:43:11 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-08-31 03:43:11 +0300
commitb8a96d789253c91093476f898611d5903799e84e (patch)
tree510bad1358bc443a0b47a1fd8c9d55057c4fa411 /libbutl/regex.txx
parent0cf84e1f006988c114bdca36715d3a2c0601a7d5 (diff)
Fix regex_replace_ex() to ignore unmatched sub-expression references
Diffstat (limited to 'libbutl/regex.txx')
-rw-r--r--libbutl/regex.txx10
1 files changed, 6 insertions, 4 deletions
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<size_t> (si) < m.size ())
+ if (static_cast<size_t> (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<size_t> (si) < m.size ())
+ if (static_cast<size_t> (si) < m.size () && m[si].matched)
append_str (m[si].first, m[si].second);
}
else