diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-06-27 19:22:33 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-06-27 19:22:33 +0300 |
commit | 4dabcf0062bc4bdfa807f7b8952eac649c9d65b5 (patch) | |
tree | 65efed57d70472bee71e8c8efe259d60b03b9d58 /libbutl/regex.txx | |
parent | aabb1b516a89366247bad3b8b927ab33bd9114d0 (diff) |
Add support for format_no_copy flag in regex_replace_ex()
Diffstat (limited to 'libbutl/regex.txx')
-rw-r--r-- | libbutl/regex.txx | 24 |
1 files changed, 18 insertions, 6 deletions
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<str_it>; - 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); } } |