From 4e57c877885ae552b574f9b69b2796cc06a7c866 Mon Sep 17 00:00:00 2001 From: Joachim Schmitz Date: Sun, 8 Sep 2024 16:53:58 +0200 Subject: [PATCH] Fix GH#24553: MusicXML: A title like "Jazz Piece No. 5" get interpreted as a subtitle Backport of #24555 and (a part of) #22056, the latter having caused a bug fixed by the former --- importexport/musicxml/importmxmlpass1.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/importexport/musicxml/importmxmlpass1.cpp b/importexport/musicxml/importmxmlpass1.cpp index 3570b904d808b..61897d9622c0e 100644 --- a/importexport/musicxml/importmxmlpass1.cpp +++ b/importexport/musicxml/importmxmlpass1.cpp @@ -747,21 +747,18 @@ static void inferFromTitle(QString& title, QString& inferredSubtitle, QString& i QStringList subtitleLines; QStringList creditLines; QStringList titleLines = title.split(QRegularExpression("\\n")); - for (int i = titleLines.length() - 1; i > 0; --i) { - QString line = titleLines[i]; + int nrOfTitleLines = titleLines.size(); + if (nrOfTitleLines == 1) + return; + for (int i = nrOfTitleLines; i > 0; --i) { + QString line = titleLines[i - 1]; if (isLikelyCreditText(line, true)) { - for (int j = titleLines.length() - 1; j >= i; --j) { - creditLines.push_front(titleLines[j]); - titleLines.removeAt(j); - } - continue; + creditLines.insert(0, line); + titleLines.erase(titleLines.begin() + i - 1); } if (isLikelySubtitleText(line, true)) { - for (int j = titleLines.length() - 1; j >= i; --j) { - subtitleLines.push_front(titleLines[j]); - titleLines.removeAt(j); - } - continue; + subtitleLines.insert(0, line); + titleLines.erase(titleLines.begin() + i - 1); } } title = titleLines.join("\n");