Skip to content

Commit 8a12c96

Browse files
committed
fix substring pos calculation
1 parent 521868f commit 8a12c96

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/server/utils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,10 @@ static std::pair<size_t, int> find_first_substring(const std::string &haystack,
498498

499499
for (unsigned int i = 0; i < needles.size(); ++i) {
500500
const std::string & start_string = needles[i];
501-
found_pos = haystack.find(start_string,search_pos);
502-
if (found_pos != std::string::npos) {
501+
auto needle_pos = haystack.find(start_string,search_pos);
502+
if (needle_pos != std::string::npos && (found_pos == std::string::npos || needle_pos < found_pos) ) {
503+
found_pos = needle_pos;
503504
found_idx = i;
504-
break;
505505
}
506506
}
507507

0 commit comments

Comments
 (0)