From b0180547ae4a076785d80ccbdce9df4fa57a26e2 Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Mon, 20 Apr 2020 21:18:40 +0200 Subject: [PATCH] Fix Regex::replace_all to actually do something --- src/script/functions/regex.cpp | 3 +-- src/util/regex.cpp | 6 ++---- src/util/regex.hpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/script/functions/regex.cpp b/src/script/functions/regex.cpp index 00242db0..213a0693 100644 --- a/src/script/functions/regex.cpp +++ b/src/script/functions/regex.cpp @@ -128,8 +128,7 @@ SCRIPT_FUNCTION_WITH_SIMPLIFY(replace) { SCRIPT_RETURN(replacer.apply(ctx, input)); } else { // simple replacing - replacer.match->replace_all(&input, replacer.replacement_string); - SCRIPT_RETURN(input); + SCRIPT_RETURN(replacer.match->replace_all(input, replacer.replacement_string)); } } SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(replace) { diff --git a/src/util/regex.cpp b/src/util/regex.cpp index e7cae8c1..6bd9ce1b 100644 --- a/src/util/regex.cpp +++ b/src/util/regex.cpp @@ -24,10 +24,8 @@ void Regex::assign(const String& code) { } } -void Regex::replace_all(String* input, const String& format) { - wxStdString std_string = toStdString(*input); - regex_replace(std_string, regex, toStdString(format), boost::format_sed); - *input = std_string; +String Regex::replace_all(const String& input, const String& format) const { + return regex_replace(toStdString(input), regex, toStdString(format), boost::format_sed); } #else // USE_BOOST_REGEX diff --git a/src/util/regex.hpp b/src/util/regex.hpp index bf6614ba..b1f55ca3 100644 --- a/src/util/regex.hpp +++ b/src/util/regex.hpp @@ -85,7 +85,7 @@ inline bool matches(Results& results, const String::const_iterator& begin, const String::const_iterator& end) const { return regex_search(begin, end, results, regex); } - void replace_all(String* input, const String& format); + String replace_all(const String& input, const String& format) const; inline bool empty() const { return regex.empty();