From abc8edebfd52af1c5211aaf1ec8f531094d784b4 Mon Sep 17 00:00:00 2001 From: Joachim Schmitz Date: Tue, 18 Jun 2024 12:39:28 +0200 Subject: [PATCH] Check for non-breaking space in XML regexes (Small) part of #23231 / https://github.com/Jojo-Schmitz/MuseScore/pull/506 --- importexport/musicxml/importmxmlpass2.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/importexport/musicxml/importmxmlpass2.cpp b/importexport/musicxml/importmxmlpass2.cpp index e1f6fa1f01613..b7fc1e3a28aad 100644 --- a/importexport/musicxml/importmxmlpass2.cpp +++ b/importexport/musicxml/importmxmlpass2.cpp @@ -3905,7 +3905,7 @@ bool MusicXMLParserDirection::isLikelyFingering() const if (!preferences.getBool(PREF_IMPORT_MUSICXML_IMPORTINFERTEXTTYPE)) return false; // One or more newline-separated digits (or changes), possibly lead or trailed by whitespace - static const QRegularExpression re("^\\s*[0-5pimac](?:[-–][0-5pimac])?(?:\\n[0-5pimac](?:[-–][0-5pimac])?)*\\s*$"); + static const QRegularExpression re("^(?:\\s|\u00A0)*[0-5pimac](?:[-–][0-5pimac])?(?:\\n[0-5pimac](?:[-–][0-5pimac])?)*(?:\\s|\u00A0)*$"); return _wordsText.contains(re) && _rehearsalText.isEmpty() && _metroText.isEmpty() @@ -3954,7 +3954,7 @@ bool MusicXMLParserDirection::isLikelyLegallyDownloaded(const Fraction& tick) co && _rehearsalText.isEmpty() && _metroText.isEmpty() && _tpoSound < 0.1 - && _wordsText.contains(QRegularExpression("This music has been legally downloaded\\.\\sDo not photocopy\\.")); + && _wordsText.contains(QRegularExpression("This music has been legally downloaded\\.(?:\\s|\u00A0)Do not photocopy\\.")); } bool MusicXMLParserDirection::isLikelyTempoText(const int track) const @@ -4131,16 +4131,16 @@ MusicXMLDelayedDirectionElement* MusicXMLInferredFingering::toDelayedDirection() double MusicXMLParserDirection::convertTextToNotes() { - static const QRegularExpression notesRegex("(?[yxeqhwW]\\.{0,2})(\\s*=)"); + static const QRegularExpression notesRegex("(?[yxeqhwW]\\.{0,2})((?:\\s|\u00A0)*=)"); QString notesSubstring = notesRegex.match(_wordsText).captured("note"); QList> noteSyms{{"q", QString("metNoteQuarterUp")}, // note4_Sym - {"e", QString("metNote8thUp")}, // note8_Sym - {"h", QString("metNoteHalfUp")}, // note2_Sym - {"y", QString("metNote32ndUp")}, // note32_Sym - {"x", QString("metNote16thUp")}, // note16_Sym - {"w", QString("metNoteWhole")}, - {"W", QString("metNoteDoubleWhole")}}; + {"e", QString("metNote8thUp")}, // note8_Sym + {"h", QString("metNoteHalfUp")}, // note2_Sym + {"y", QString("metNote32ndUp")}, // note32_Sym + {"x", QString("metNote16thUp")}, // note16_Sym + {"w", QString("metNoteWhole")}, + {"W", QString("metNoteDoubleWhole")}}; for (auto noteSym : noteSyms) { if (notesSubstring.contains(noteSym.first)) { notesSubstring.replace(noteSym.first, noteSym.second); @@ -4166,9 +4166,9 @@ double MusicXMLParserDirection::convertTextToNotes() bool MusicXMLParserDirection::attemptTempoTextCoercion(const Fraction& tick) { QList tempoWords{"rit", "rall", "accel", "tempo", "allegr", "poco", "molto", "più", "meno", "mosso", "rubato"}; - static const QRegularExpression re("[yxeqhwW.]+\\s*=\\s*\\d+"); + static const QRegularExpression re("[yxeqhwW.]+(?:\\s|\u00A0)*=(?:\\s|\u00A0)*\\d+"); if (_wordsText.contains(re)) { - static const QRegularExpression tempoValRegex("=\\s*(?\\d+)"); + static const QRegularExpression tempoValRegex("=(?:\\s|\u00A0)*(?\\d+)"); double tempoVal = tempoValRegex.match(_wordsText).captured("tempo").toDouble(); double noteVal = convertTextToNotes() * 60.0; _tpoSound = tempoVal / noteVal;