From 0cf84e1f006988c114bdca36715d3a2c0601a7d5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 30 Aug 2017 10:23:06 +0300 Subject: Generalize regex_replace_ex() function --- libbutl/regex.hxx | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'libbutl/regex.hxx') diff --git a/libbutl/regex.hxx b/libbutl/regex.hxx index e4fd6a7..2105f05 100644 --- a/libbutl/regex.hxx +++ b/libbutl/regex.hxx @@ -14,13 +14,18 @@ namespace butl { - // Like std::regex_match() but extends the standard ECMA-262 - // substitution escape sequences with a subset of Perl sequences: + // 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: // - // \\, \u, \l, \U, \L, \E, \1, ..., \9 + // void + // append(basic_string::iterator begin, basic_string::iterator end); // - // Also return the resulting string as well as whether the search - // succeeded. + // The regex semantics 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 // // Notes and limitations: // @@ -34,6 +39,19 @@ namespace butl // C++ locale (which is, unless changed, is the same as C locale and // both default to the POSIX locale aka "C"). // + 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); + + // As above but concatenate non-matched substrings and matched substring + // replacements into a string returning it as well as whether the search + // succeeded. + // template std::pair, bool> regex_replace_ex (const std::basic_string&, @@ -52,6 +70,7 @@ namespace std operator<< (ostream&, const regex_error&); } +#include #include #endif // LIBBUTL_REGEX_HXX -- cgit v1.1