From ca9053955195bfc29c75d5c073f56b6949041381 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 b0ad690510e3c..1c4cc3673701e 100644 --- a/importexport/musicxml/importmxmlpass1.cpp +++ b/importexport/musicxml/importmxmlpass1.cpp @@ -731,21 +731,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");