refactor: use string views in ReplaceAll

PR #25803 changed these parameters to `const std::string&` for `std::regex_replace()`.
The literal implementation no longer needs owned strings, so restore the original `std::string_view` interface.
This commit is contained in:
Lőrinc
2026-08-20 13:11:34 -07:00
parent 469b0e59a2
commit 1f9dfabef6
3 changed files with 4 additions and 3 deletions

View File

@@ -300,7 +300,7 @@ BOOST_AUTO_TEST_CASE(util_Join)
BOOST_AUTO_TEST_CASE(util_ReplaceAll)
{
const std::string original("A test \"%s\" string '%s'.");
auto test_replaceall{[](std::string test, const std::string& search, const std::string& substitute, const std::string& expected) {
auto test_replaceall{[](std::string test, std::string_view search, std::string_view substitute, std::string_view expected) {
ReplaceAll(test, search, substitute);
BOOST_CHECK_EQUAL(test, expected);
}};

View File

@@ -8,9 +8,10 @@
#include <memory>
#include <stdexcept>
#include <string>
#include <string_view>
namespace util {
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute)
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute)
{
if (search.empty()) return;
auto pos{in_out.find(search)};

View File

@@ -99,7 +99,7 @@ struct ConstevalFormatString {
};
/// Replace every non-overlapping occurrence of `search` with `substitute`, treating both literally; the replacement text is not searched again.
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute);
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute);
/** Split a string on any char found in separators, returning a vector.
*