From 08ea68dc1f3ffc387796addaacaeb40e4e566763 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 8 Oct 2017 11:16:03 +0800 Subject: [PATCH] Regex: Fix handling of match_prev_avail for boost regex We were passing around iterators that were not allowed to go before the begin iterator. --- src/regex.hh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/regex.hh b/src/regex.hh index 3d067b0b..eecb947d 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -180,7 +180,8 @@ bool regex_search(It begin, It end, const Regex& re, { try { - bool matched = boost::regex_search>({begin, begin, end}, {end, begin, end}, re, flags); + auto first = (flags & RegexConstant::match_prev_avail) ? begin-1 : begin; + bool matched = boost::regex_search>({begin, first, end}, {end, first, end}, re, flags); if (re.impl() and matched != regex_search(begin, end, *re.impl(), convert_flags(flags))) regex_mismatch(re); return matched; @@ -197,7 +198,8 @@ bool regex_search(It begin, It end, MatchResults& res, const Regex& re, { try { - bool matched = boost::regex_search>({begin, begin, end}, {end, begin, end}, res, re, flags); + auto first = (flags & RegexConstant::match_prev_avail) ? begin-1 : begin; + bool matched = boost::regex_search>({begin, first, end}, {end, first, end}, res, re, flags); Vector captures; if (re.impl() and matched != regex_search(begin, end, captures, *re.impl(), convert_flags(flags))) regex_mismatch(re);