Skip to content

Commit b1bcd30

Browse files
authored
fix stop regression (#11543)
1 parent 5783575 commit b1bcd30

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

examples/server/utils.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,14 @@ static bool ends_with(const std::string & str, const std::string & suffix) {
484484

485485
static size_t find_partial_stop_string(const std::string &stop, const std::string &text) {
486486
if (!text.empty() && !stop.empty()) {
487-
auto it = std::find(stop.rbegin(), stop.rend(), text.back());
488-
while (it != stop.rend()) {
489-
size_t length = std::distance(it, stop.rend());
490-
if (text.length() >= length && 0 == text.compare(text.length() - length, length, stop)) {
491-
return text.length() - length;
487+
const char text_last_char = text.back();
488+
for (int64_t char_index = stop.size() - 1; char_index >= 0; char_index--) {
489+
if (stop[char_index] == text_last_char) {
490+
const std::string current_partial = stop.substr(0, char_index + 1);
491+
if (ends_with(text, current_partial)) {
492+
return text.size() - char_index - 1;
493+
}
492494
}
493-
it = std::find(std::next(it), stop.rend(), text.back());
494495
}
495496
}
496497

0 commit comments

Comments
 (0)