From df36e435848bb5e93ad6bf15ff326af4ec1badfc Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Mon, 16 Oct 2023 14:02:18 -0300 Subject: [PATCH] GH-38282 [C++]: Implement ReplaceString with the right type signature (#38283) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Rationale for this change The type signature of `ReplaceString` should be identical when arrow is compiled with or without `ARROW_WITH_RE2`. ### What changes are included in this PR? The right signature + delegating to the implementation that takes `re2::StringPiece`. The conversion should be a no-op when compiled and optimized. ### Are these changes tested? By existing tests and CI checks. * Closes: #38282 Authored-by: Felipe Oliveira Carvalho Signed-off-by: Raúl Cumplido --- cpp/src/arrow/compute/kernels/scalar_string_ascii.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc b/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc index 90f5d40b984f4..6764845dfca81 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc +++ b/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc @@ -2063,7 +2063,13 @@ struct RegexSubstringReplacer { regex_find_("(" + options_.pattern + ")", MakeRE2Options()), regex_replacement_(options_.pattern, MakeRE2Options()) {} - Status ReplaceString(re2::StringPiece s, TypedBufferBuilder* builder) const { + Status ReplaceString(std::string_view s, TypedBufferBuilder* builder) const { + re2::StringPiece piece(s.data(), s.length()); + return ReplaceStringImpl(piece, builder); + } + + Status ReplaceStringImpl(re2::StringPiece s, + TypedBufferBuilder* builder) const { re2::StringPiece replacement(options_.replacement); // If s is empty, then it's essentially global