From 4dabcf0062bc4bdfa807f7b8952eac649c9d65b5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 27 Jun 2017 19:22:33 +0300 Subject: Add support for format_no_copy flag in regex_replace_ex() --- libbutl/regex.txx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'libbutl/regex.txx') diff --git a/libbutl/regex.txx b/libbutl/regex.txx index cb8cfe0..9c6342b 100644 --- a/libbutl/regex.txx +++ b/libbutl/regex.txx @@ -20,8 +20,8 @@ namespace butl using str_it = typename string_type::const_iterator; using regex_it = regex_iterator; - bool first_only ((flags & std::regex_constants::format_first_only) == - std::regex_constants::format_first_only); + bool first_only ((flags & std::regex_constants::format_first_only) != 0); + bool no_copy ((flags & std::regex_constants::format_no_copy) != 0); locale cl; // Copy of the global C++ locale. string_type r; @@ -41,11 +41,19 @@ namespace butl // Copy the preceeding unmatched substring, save the beginning of the // one that follows. // - r.append (ub, m.prefix ().second); - ub = m.suffix ().first; + if (!no_copy) + { + r.append (ub, m.prefix ().second); + ub = m.suffix ().first; + } if (first_only && i != b) - r.append (m[0].first, m[0].second); // Append matched substring. + { + // Append matched substring. + // + if (!no_copy) + r.append (m[0].first, m[0].second); + } else { // The standard implementation calls m.format() here. We perform our @@ -212,7 +220,11 @@ namespace butl } } - r.append (ub, s.end ()); // Append the rightmost non-matched substring. + // Append the rightmost non-matched substring. + // + if (!no_copy) + r.append (ub, s.end ()); + return make_pair (move (r), match); } } -- cgit v1.1