From 95c579df686f115c0fd3697f2723fa73476c4584 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 23 Mar 2021 18:50:55 +0300 Subject: Add regex_replace_parse() overloads --- libbutl/regex.mxx | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'libbutl/regex.mxx') diff --git a/libbutl/regex.mxx b/libbutl/regex.mxx index 84b024f..b5490b1 100644 --- a/libbutl/regex.mxx +++ b/libbutl/regex.mxx @@ -14,8 +14,9 @@ #include // pair #include -#include // size_t -#include // move(), make_pair() +#include // size_t +#include // move(), make_pair() +#include // invalid_argument #endif #if defined(__clang__) @@ -93,6 +94,37 @@ LIBBUTL_MODEXPORT namespace butl regex_replace_match (const std::basic_string&, const std::basic_regex&, const std::basic_string& fmt); + + // Parse the '///' replacement string into the regex/format + // pair. Other character can be used as a delimiter instead of '/'. Throw + // std::invalid_argument or std::regex_error on parsing error. + // + // Note: escaping of the delimiter character is not (yet) supported. + // + template + std::pair, std::basic_string> + regex_replace_parse (const std::basic_string&, + std::regex_constants::syntax_option_type = + std::regex_constants::ECMAScript); + + template + std::pair, std::basic_string> + regex_replace_parse (const C*, + std::regex_constants::syntax_option_type = + std::regex_constants::ECMAScript); + + template + std::pair, std::basic_string> + regex_replace_parse (const C*, size_t, + std::regex_constants::syntax_option_type = + std::regex_constants::ECMAScript); + + // As above but return string instead of regex and do not fail if there is + // text after the last delimiter instead returning its position. + // + template + std::pair, std::basic_string> + regex_replace_parse (const C*, size_t, size_t& end); } LIBBUTL_MODEXPORT namespace std -- cgit v1.1