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,56 +376,62 @@ 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) {
switch (str[newLine - 1]){ switch (str[newLine - 1]) {
case '\x05'://COLOR case '\x05': // COLOR
case '\x06'://SHIFT case '\x06': // SHIFT
case '\x07'://TEXTID case '\x07': // TEXTID
case '\x0C'://BOX_BREAK_DELAYED case '\x0C': // BOX_BREAK_DELAYED
case '\x0E'://FADE case '\x0E': // FADE
case '\x11'://FADE2 case '\x11': // FADE2
case '\x12'://SFX case '\x12': // SFX
case '\x13'://ITEM_ICON case '\x13': // ITEM_ICON
case '\x14'://TEXT_SPEED case '\x14': // TEXT_SPEED
case '\x15'://BACKGROUND case '\x15': // BACKGROUND
case '\x1E'://POINTS/HIGH_SCORE case '\x1E': // POINTS/HIGH_SCORE
done = false; done = false;
break; break;
default: default:
break; break;
} }
if (newLine > 1){ if (newLine > 1) {
switch (str[newLine - 2]){ switch (str[newLine - 2]) {
case '\x07'://TEXTID case '\x07': // TEXTID
case '\x11'://FADE2 case '\x11': // FADE2
case '\x12'://SFX case '\x12': // SFX
case '\x15'://BACKGROUND case '\x15': // BACKGROUND
done = false; done = false;
break; break;
default: default:
break; break;
} }
if (newLine > 2){ if (newLine > 2) {
if (str[newLine - 3] == '\x15'){//BACKGROUND if (str[newLine - 3] == '\x15') { // BACKGROUND
done = false; done = false;
} }
} }
} }
} }
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;
} }