From 06e915be138b0638e30083f84cecda0eb1bfc895 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 19 Jun 2018 15:30:22 +0300 Subject: Add regex_replace_match() and rename regex_replace_ex() to regex_replace_search() --- libbutl/regex.mxx | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'libbutl/regex.mxx') diff --git a/libbutl/regex.mxx b/libbutl/regex.mxx index 741b818..7fa0155 100644 --- a/libbutl/regex.mxx +++ b/libbutl/regex.mxx @@ -40,16 +40,9 @@ import std.regex; // @@ MOD TODO should probably be re-exported. LIBBUTL_MODEXPORT namespace butl { - // Call specified append() function for non-matched substrings and matched - // substring replacements returning true if search succeeded. The function - // must be callable with the following signature: - // - // void - // append(basic_string::iterator begin, basic_string::iterator end); - // - // The regex semantics is like that of std::regex_replace() extended the - // standard ECMA-262 substitution escape sequences with a subset of Perl - // sequences: + // The regex semantics for the following functions is like that of + // std::regex_replace() extended the standard ECMA-262 substitution escape + // sequences with a subset of Perl sequences: // // \\, \u, \l, \U, \L, \E, \1, ..., \9 // @@ -65,14 +58,22 @@ LIBBUTL_MODEXPORT namespace butl // C++ locale (which is, unless changed, is the same as C locale and // both default to the POSIX locale aka "C"). // + + // Call specified append() function for non-matched substrings and matched + // substring replacements returning true if search succeeded. The function + // must be callable with the following signature: + // + // void + // append(basic_string::iterator begin, basic_string::iterator end); + // template bool - regex_replace_ex (const std::basic_string&, - const std::basic_regex&, - const std::basic_string& fmt, - F&& append, - std::regex_constants::match_flag_type = - std::regex_constants::match_default); + regex_replace_search (const std::basic_string&, + const std::basic_regex&, + const std::basic_string& fmt, + F&& append, + std::regex_constants::match_flag_type = + std::regex_constants::match_default); // As above but concatenate non-matched substrings and matched substring // replacements into a string returning it as well as whether the search @@ -80,11 +81,19 @@ LIBBUTL_MODEXPORT namespace butl // template std::pair, bool> - regex_replace_ex (const std::basic_string&, - const std::basic_regex&, - const std::basic_string& fmt, - std::regex_constants::match_flag_type = - std::regex_constants::match_default); + regex_replace_search (const std::basic_string&, + const std::basic_regex&, + const std::basic_string& fmt, + std::regex_constants::match_flag_type = + std::regex_constants::match_default); + + // Match the entire string and, if it matches, return the string replacement. + // + template + std::pair, bool> + regex_replace_match (const std::basic_string&, + const std::basic_regex&, + const std::basic_string& fmt); } LIBBUTL_MODEXPORT namespace std -- cgit v1.1