Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix strings replace for adjacent, identical multi-byte UTF-8 character targets #14235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/src/strings/replace/replace.cu
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct replace_row_parallel_fn {
} else {
bytes += d_repl.size_bytes() - d_target.size_bytes();
}
position = d_str.find(d_target, position + d_target.size_bytes());
position = d_str.find(d_target, position + d_target.length());
--max_n;
}
if (out_ptr) // copy whats left (or right depending on your point of view)
Expand Down
22 changes: 22 additions & 0 deletions cpp/tests/strings/replace_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ TEST_F(StringsReplaceTest, ReplaceEndOfString)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTest, ReplaceAdjacentMultiByteTarget)
{
auto input = cudf::test::strings_column_wrapper({"ééééééé", "eéeéeée", "eeeeeee"});
auto strings_view = cudf::strings_column_view(input);
// replace all occurrences of 'é' with 'e'
cudf::test::strings_column_wrapper expected({"eeeeeee", "eeeeeee", "eeeeeee"});

auto stream = cudf::get_default_stream();
auto mr = rmm::mr::get_current_device_resource();

auto target = cudf::string_scalar("é", true, stream);
auto repl = cudf::string_scalar("e", true, stream);
auto results = cudf::strings::replace(strings_view, target, repl);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
results = cudf::strings::detail::replace<algorithm::CHAR_PARALLEL>(
strings_view, target, repl, -1, stream, mr);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
results = cudf::strings::detail::replace<algorithm::ROW_PARALLEL>(
strings_view, target, repl, -1, stream, mr);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTest, ReplaceSlice)
{
std::vector<char const*> h_strings{"Héllo", "thesé", nullptr, "ARE THE", "tést strings", ""};
Expand Down