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 replace error when regex has only zero match quantifiers #10760

Merged
15 changes: 8 additions & 7 deletions cpp/src/strings/replace/replace_re.cu
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ struct replace_regex_fn {
return;
}

auto const d_str = d_strings.element<string_view>(idx);
auto nbytes = d_str.size_bytes(); // number of bytes in input string
auto mxn = maxrepl < 0 ? d_str.length() + 1 : maxrepl; // max possible replaces for this string
auto in_ptr = d_str.data(); // input pointer (i)
auto out_ptr = d_chars ? d_chars + d_offsets[idx] // output pointer (o)
: nullptr;
auto const d_str = d_strings.element<string_view>(idx);
auto const nchars = d_str.length();
auto nbytes = d_str.size_bytes(); // number of bytes in input string
auto mxn = maxrepl < 0 ? nchars + 1 : maxrepl; // max possible replaces for this string
auto in_ptr = d_str.data(); // input pointer (i)
auto out_ptr = d_chars ? d_chars + d_offsets[idx] // output pointer (o)
: nullptr;
size_type last_pos = 0;
int32_t begin = 0; // these are for calling prog.find
int32_t end = -1; // matches final word-boundary if at the end of the string

// copy input to output replacing strings as we go
while (mxn-- > 0) { // maximum number of replaces
while (mxn-- > 0 && begin <= nchars) { // maximum number of replaces

if (prog.is_empty() || prog.find<stack_size>(idx, d_str, begin, end) <= 0) {
break; // no more matches
Expand Down