Fix find newline looping to have additional break early cases (#4614)

This commit is contained in:
Archez 2024-12-04 13:01:08 -05:00 committed by GitHub
parent b442c15322
commit 9b169af3f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -376,10 +376,15 @@ static size_t NextLineLength(const std::string* textStr, const size_t lastNewlin
} }
} }
size_t CustomMessage::FindNEWLINE(std::string& str, size_t lastNewline) const { size_t CustomMessage::FindNEWLINE(std::string& str, size_t lastNewline) const {
size_t newLine = str.find(NEWLINE()[0], lastNewline); size_t newLine = str.find(NEWLINE()[0], lastNewline);
bool done; bool done;
// Bail out early
if (newLine == std::string::npos) {
return newLine;
}
do { do {
done = true; done = true;
if (newLine != 0) { if (newLine != 0) {
@ -420,12 +425,13 @@ size_t CustomMessage::FindNEWLINE(std::string& str, size_t lastNewline) const {
} }
if (!done) { if (!done) {
newLine = str.find(NEWLINE()[0], newLine + 1); newLine = str.find(NEWLINE()[0], newLine + 1);
if (newLine != std::string::npos){ if (newLine == std::string::npos) {
// if we reach the end of the string, quit now to save a loop // if we reach the end of the string, quit now to save a loop
done = true; done = true;
} }
} }
} while (!done); } while (!done);
return newLine; return newLine;
} }