Replace uses of QRegExp with QRegularExpression

QRegExp is deprecated in Qt 6.
This commit is contained in:
Casper Jeukendrup 2021-07-06 23:53:03 +02:00 committed by Igor Korsukov
parent 17868b7713
commit 98c7a77487
22 changed files with 249 additions and 224 deletions

View File

@ -35,7 +35,6 @@ It is best to use a tool to determine the most commonly used inclusions.
See https://github.com/musescore/musescore_devtools/tree/main/include-what-you-use
*/
// Std includes
#include <memory> //413
#include <vector> //401
@ -91,7 +90,6 @@ See https://github.com/musescore/musescore_devtools/tree/main/include-what-you-u
#include <QFileInfo> //40
#include <QSizeF> //39
#include <QSet> //39
#include <QRegExp> //38
#include <QRect> //38
#include <QDebug> //35
#include <QSize> //34
@ -109,4 +107,3 @@ See https://github.com/musescore/musescore_devtools/tree/main/include-what-you-u
#include <QXmlStreamAttributes> //22
#endif //MU_PCH_H

View File

@ -20,12 +20,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "chordlist.h"
#include <QRegularExpression>
#include "config.h"
#include "mscore.h"
#include "pitchspelling.h"
#include "score.h"
#include "xml.h"
#include "pitchspelling.h"
#include "mscore.h"
using namespace mu;
@ -497,7 +500,7 @@ void ParsedChord::configure(const ChordList* cl)
void ParsedChord::correctXmlText(const QString& s)
{
_xmlText.remove(QRegExp("[0-9]"));
_xmlText.remove(QRegularExpression("[0-9]"));
if (s != "") {
int pos = _xmlText.lastIndexOf(')');
if (pos == -1) {
@ -1200,7 +1203,7 @@ bool ParsedChord::parse(const QString& s, const ChordList* cl, bool syntaxOnly,
QStringList altList = _xmlDegrees.filter("alt");
for (const QString& d : qAsConst(altList)) {
QString unalt(d);
unalt.replace(QRegExp("alt[b#]"), "add");
unalt.replace(QRegularExpression("alt[b#]"), "add");
if (_xmlDegrees.removeAll(unalt) > 0) {
QString alt(d);
alt.replace("alt", "add");

View File

@ -21,38 +21,41 @@
*/
#include "excerpt.h"
#include "score.h"
#include "part.h"
#include "xml.h"
#include "staff.h"
#include "box.h"
#include "textframe.h"
#include "style.h"
#include "page.h"
#include "text.h"
#include "slur.h"
#include "tie.h"
#include "sig.h"
#include "tempo.h"
#include "measure.h"
#include "rest.h"
#include "stafftype.h"
#include "tuplet.h"
#include "chord.h"
#include "note.h"
#include "lyrics.h"
#include "segment.h"
#include "textline.h"
#include "tupletmap.h"
#include "tiemap.h"
#include "layoutbreak.h"
#include "harmony.h"
#include "beam.h"
#include "utils.h"
#include "tremolo.h"
#include <QRegularExpression>
#include "barline.h"
#include "undo.h"
#include "beam.h"
#include "box.h"
#include "bracketItem.h"
#include "chord.h"
#include "harmony.h"
#include "layoutbreak.h"
#include "lyrics.h"
#include "measure.h"
#include "note.h"
#include "page.h"
#include "part.h"
#include "rest.h"
#include "score.h"
#include "segment.h"
#include "sig.h"
#include "slur.h"
#include "staff.h"
#include "stafftype.h"
#include "style.h"
#include "tempo.h"
#include "text.h"
#include "textframe.h"
#include "textline.h"
#include "tie.h"
#include "tiemap.h"
#include "tremolo.h"
#include "tuplet.h"
#include "tupletmap.h"
#include "undo.h"
#include "utils.h"
#include "xml.h"
using namespace mu;
@ -1395,8 +1398,9 @@ QString Excerpt::formatTitle(const QString& partName, const QList<Excerpt*>& exc
e->setTitle(e->title() + " 1");
}
QRegExp rx("^(.+)\\s\\d+$");
if (rx.indexIn(e->title()) > -1 && rx.cap(1) == name) {
QRegularExpression regex("^(.+)\\s\\d+$");
QRegularExpressionMatch match = regex.match(e->title());
if (match.hasMatch() && match.capturedTexts()[1] == name) {
count++;
}
}

View File

@ -409,7 +409,7 @@ void Lyrics::paste(EditData& ed, const QString& txt)
{
MuseScoreView* scoreview = ed.view();
QString regex = QString("[^\\S") + QChar(0xa0) + QChar(0x202F) + "]+";
QStringList sl = txt.split(QRegExp(regex), Qt::SkipEmptyParts);
QStringList sl = txt.split(QRegularExpression(regex), Qt::SkipEmptyParts);
if (sl.empty()) {
return;
}

View File

@ -22,6 +22,8 @@
#include <cmath>
#include <QRegularExpression>
#include "xml.h"
#include "score.h"
#include "staff.h"
@ -1257,9 +1259,10 @@ static QString ReadStyleName206(QString xmlTag)
{
QString s;
if (xmlTag.contains("<style>")) {
QRegExp re("<style>([^<]+)</style>");
if (re.indexIn(xmlTag) > -1) {
s = re.cap(1);
QRegularExpression regex("<style>([^<]+)</style>");
QRegularExpressionMatch match = regex.match(xmlTag);
if (match.hasMatch()) {
s = match.captured();
}
}
return s;

View File

@ -23,6 +23,7 @@
#include <cmath>
#include <QDir>
#include <QBuffer>
#include <QRegularExpression>
#include "config.h"
#include "score.h"
@ -52,6 +53,7 @@
#include "scoreorder.h"
#include "preferences.h"
#include "utils.h"
#include "sig.h"
#include "undo.h"
@ -943,49 +945,46 @@ Score::FileError MasterScore::loadMsc(QString name, QIODevice* io, bool ignoreVe
void MasterScore::parseVersion(const QString& val)
{
QRegExp re("(\\d+)\\.(\\d+)\\.(\\d+)");
int v1, v2, v3, rv1, rv2, rv3;
if (re.indexIn(VERSION) != -1) {
QStringList sl = re.capturedTexts();
if (sl.size() == 4) {
v1 = sl[1].toInt();
v2 = sl[2].toInt();
v3 = sl[3].toInt();
if (re.indexIn(val) != -1) {
sl = re.capturedTexts();
if (sl.size() == 4) {
rv1 = sl[1].toInt();
rv2 = sl[2].toInt();
rv3 = sl[3].toInt();
int appVersion = version();
int currentVersion = v1 * 10000 + v2 * 100 + v3;
int readVersion = rv1 * 10000 + rv2 * 100 + rv3;
if (readVersion > currentVersion) {
qDebug("read future version");
}
}
} else {
QRegExp re1("(\\d+)\\.(\\d+)");
if (re1.indexIn(val) != -1) {
sl = re.capturedTexts();
if (sl.size() == 3) {
rv1 = sl[1].toInt();
rv2 = sl[2].toInt();
QRegularExpression majorMinorPatchRegEx("(\\d+)\\.(\\d+)\\.(\\d+)");
QRegularExpressionMatch scoreVersionMatch = majorMinorPatchRegEx.match(val);
int currentVersion = v1 * 10000 + v2 * 100 + v3;
int readVersion = rv1 * 10000 + rv2 * 100;
if (readVersion > currentVersion) {
qDebug("read future version");
}
}
} else {
qDebug("1cannot parse <%s>", qPrintable(val));
}
if (scoreVersionMatch.hasMatch()) {
QStringList scoreVersionList = scoreVersionMatch.capturedTexts();
if (scoreVersionList.size() == 4) {
int rv1 = scoreVersionList[1].toInt();
int rv2 = scoreVersionList[2].toInt();
int rv3 = scoreVersionList[3].toInt();
int scoreVersion = rv1 * 10000 + rv2 * 100 + rv3;
if (scoreVersion > appVersion) {
qDebug("Parsed score version is higher than current app version: %d vs %d", scoreVersion, appVersion);
}
return;
}
} else {
qDebug("2cannot parse <%s>", VERSION);
}
QRegularExpression majorMinorRegEx("(\\d+)\\.(\\d+)");
scoreVersionMatch = majorMinorRegEx.match(val);
if (scoreVersionMatch.hasMatch()) {
QStringList scoreVersionList = scoreVersionMatch.capturedTexts();
if (scoreVersionList.size() == 3) {
int rv1 = scoreVersionList[1].toInt();
int rv2 = scoreVersionList[2].toInt();
int scoreVersion = rv1 * 10000 + rv2 * 100;
if (scoreVersion > appVersion) {
qDebug("Parsed score version is higher than current app version: %d vs %d", scoreVersion, appVersion);
}
return;
}
}
qDebug("Cannot parse score version: %s", qPrintable(val));
}
//---------------------------------------------------------

View File

@ -22,15 +22,17 @@
#include <cmath>
#include "score.h"
#include "tempotext.h"
#include "tempo.h"
#include "system.h"
#include <QRegularExpression>
#include "measure.h"
#include "staff.h"
#include "xml.h"
#include "undo.h"
#include "musescoreCore.h"
#include "score.h"
#include "staff.h"
#include "system.h"
#include "tempo.h"
#include "tempotext.h"
#include "undo.h"
#include "xml.h"
using namespace mu;
@ -105,9 +107,8 @@ void TempoText::read(XmlReader& e)
qreal TempoText::tempoBpm() const
{
//! NOTE: find tempo in format " = 180"
QRegExp regExp("\\s*=\\s*(\\d+[.]{0,1}\\d*)");
regExp.indexIn(xmlText());
QStringList matches = regExp.capturedTexts();
QRegularExpression regex("\\s*=\\s*(\\d+[.]{0,1}\\d*)");
QStringList matches = regex.match(xmlText()).capturedTexts();
if (matches.empty() || matches.size() < 1) {
return 0;
@ -171,12 +172,12 @@ int TempoText::findTempoDuration(const QString& s, int& len, TDuration& dur)
len = 0;
dur = TDuration();
for (const auto& i : tp) {
QRegExp re(i.pattern);
int pos = re.indexIn(s);
if (pos != -1) {
len = re.matchedLength();
QRegularExpression regex(i.pattern);
QRegularExpressionMatch match = regex.match(s);
if (match.hasMatch()) {
len = match.capturedLength();
dur = i.d;
return pos;
return match.capturedStart();
}
}
return -1;
@ -308,20 +309,21 @@ void TempoText::undoChangeProperty(Pid id, const QVariant& v, PropertyFlags ps)
void TempoText::updateTempo()
{
// cache regexp, they are costly to create
static QHash<QString, QRegExp> regexps;
static QHash<QString, QRegExp> regexps2;
static QHash<QString, QRegularExpression> regexps;
static QHash<QString, QRegularExpression> regexps2;
QString s = plainText();
s.replace(",", ".");
s.replace("<sym>space</sym>", " ");
for (const TempoPattern& pa : tp) {
QRegExp re;
QRegularExpression re;
if (!regexps.contains(pa.pattern)) {
re = QRegExp(QString("%1\\s*=\\s*(\\d+[.]{0,1}\\d*)\\s*").arg(pa.pattern));
re = QRegularExpression(QString("%1\\s*=\\s*(\\d+[.]{0,1}\\d*)\\s*").arg(pa.pattern));
regexps[pa.pattern] = re;
}
re = regexps.value(pa.pattern);
if (re.indexIn(s) != -1) {
QStringList sl = re.capturedTexts();
QRegularExpressionMatch match = re.match(s);
if (match.hasMatch()) {
QStringList sl = match.capturedTexts();
if (sl.size() == 2) {
qreal nt = qreal(sl[1].toDouble()) * pa.f;
if (nt != _tempo) {
@ -335,13 +337,14 @@ void TempoText::updateTempo()
} else {
for (const TempoPattern& pa2 : tp) {
QString key = QString("%1_%2").arg(pa.pattern, pa2.pattern);
QRegExp re2;
QRegularExpression re2;
if (!regexps2.contains(key)) {
re2 = QRegExp(QString("%1\\s*=\\s*%2\\s*").arg(pa.pattern, pa2.pattern));
re2 = QRegularExpression(QString("%1\\s*=\\s*%2\\s*").arg(pa.pattern, pa2.pattern));
regexps2[key] = re2;
}
re2 = regexps2.value(key);
if (re2.indexIn(s) != -1) {
QRegularExpressionMatch match2 = re2.match(s);
if (match2.hasMatch()) {
_relative = pa2.f / pa.f;
_isRelative = true;
updateRelative();

View File

@ -24,6 +24,7 @@
#include <cmath>
#include <QtMath>
#include <QRegularExpression>
#include "translation.h"
@ -636,28 +637,30 @@ int searchInterval(int steps, int semitones)
return -1;
}
static int _majorVersion, _minorVersion, _updateVersion;
static int _majorVersion, _minorVersion, _patchVersion;
/*!
* Returns the program version
*
* @return
* Version in the format: MMmmuu
* Where M=Major, m=minor, and u=update
* Version in the format: MMmmpp
* Where M=Major, m=minor, and p=patch
*/
int version()
{
QRegExp re("(\\d+)\\.(\\d+)\\.(\\d+)");
if (re.indexIn(VERSION) != -1) {
QStringList sl = re.capturedTexts();
if (sl.size() == 4) {
_majorVersion = sl[1].toInt();
_minorVersion = sl[2].toInt();
_updateVersion = sl[3].toInt();
return _majorVersion * 10000 + _minorVersion * 100 + _updateVersion;
QRegularExpression versionRegEx("(\\d+)\\.(\\d+)\\.(\\d+)");
QRegularExpressionMatch versionMatch = versionRegEx.match(VERSION);
if (versionMatch.hasMatch()) {
QStringList versionStringList = versionMatch.capturedTexts();
if (versionStringList.size() == 4) {
_majorVersion = versionStringList[1].toInt();
_minorVersion = versionStringList[2].toInt();
_patchVersion = versionStringList[3].toInt();
return _majorVersion * 10000 + _minorVersion * 100 + _patchVersion;
}
}
qDebug() << "Could not parse version:" << VERSION;
return 0;
}
@ -682,17 +685,17 @@ int minorVersion()
}
//---------------------------------------------------------
// updateVersion
// patchVersion
//---------------------------------------------------------
int updateVersion()
int patchVersion()
{
version();
return _updateVersion;
return _patchVersion;
}
//---------------------------------------------------------
// updateVersion
// compareVersion
/// Up to 4 digits X.X.X.X
/// Each digit can be double XX.XX.XX.XX
/// return true if v1 < v2

View File

@ -75,7 +75,7 @@ int diatonicUpDown(Key, int pitch, int steps);
extern int version();
extern int majorVersion();
extern int minorVersion();
extern int updateVersion();
extern int patchVersion();
extern bool compareVersion(QString v1, QString v2);
extern Note* nextChordNote(Note* note);

View File

@ -21,8 +21,9 @@
*/
#include "path.h"
#include <QFileInfo>
#include <QDir>
#include <QFileInfo>
#include <QRegularExpression>
#include "stringutils.h"
@ -177,16 +178,16 @@ mu::io::path mu::io::escapeFileName(const mu::io::path& fn_)
fn = fn.simplified();
fn = fn.replace(QChar(' '), "_");
fn = fn.replace(QChar('\n'), "_");
fn = fn.replace(QChar(0xe4), "ae"); // &auml;
fn = fn.replace(QChar(0xf6), "oe"); // &ouml;
fn = fn.replace(QChar(0xfc), "ue"); // &uuml;
fn = fn.replace(QChar(0xdf), "ss"); // &szlig;
fn = fn.replace(QChar(0xc4), "Ae"); // &Auml;
fn = fn.replace(QChar(0xd6), "Oe"); // &Ouml;
fn = fn.replace(QChar(0xdc), "Ue"); // &Uuml;
fn = fn.replace(QChar(0x266d), "b"); // musical flat sign, happen in instrument names, so can happen in part (file) names
fn = fn.replace(QChar(0x266f), "#"); // musical sharp sign, can happen in titles, so can happen in score (file) names
fn = fn.replace(QRegExp("[" + QRegExp::escape("\\/:*?\"<>|") + "]"), "_"); //FAT/NTFS special chars
fn = fn.replace(QChar(0xe4), "ae"); // &auml;
fn = fn.replace(QChar(0xf6), "oe"); // &ouml;
fn = fn.replace(QChar(0xfc), "ue"); // &uuml;
fn = fn.replace(QChar(0xdf), "ss"); // &szlig;
fn = fn.replace(QChar(0xc4), "Ae"); // &Auml;
fn = fn.replace(QChar(0xd6), "Oe"); // &Ouml;
fn = fn.replace(QChar(0xdc), "Ue"); // &Uuml;
fn = fn.replace(QChar(0x266d), "b"); // musical flat sign, happen in instrument names, so can happen in part (file) names
fn = fn.replace(QChar(0x266f), "#"); // musical sharp sign, can happen in titles, so can happen in score (file) names
fn = fn.replace(QRegularExpression("[" + QRegularExpression::escape("\\/:*?\"<>|") + "]"), "_"); //FAT/NTFS special chars
return fn;
}

View File

@ -66,7 +66,7 @@ QQmlListProperty<SorterValue> SortFilterProxyModel::sorters()
void SortFilterProxyModel::refresh()
{
setFilterFixedString(filterRegExp().pattern());
setFilterFixedString(filterRegularExpression().pattern());
setSortCaseSensitivity(sortCaseSensitivity());
}
@ -146,7 +146,7 @@ void SortFilterProxyModel::fillRoleIds()
++it;
}
setFilterFixedString(filterRegExp().pattern());
setFilterFixedString(filterRegularExpression().pattern());
}
SorterValue* SortFilterProxyModel::currentSorterValue() const

View File

@ -59,9 +59,9 @@ void DoubleInputValidator::fixup(QString& string) const
floatPart.append(zeros(m_decimal - floatPart.length()));
}
if (intPart.contains(QRegExp("^0{1,3}$"))) {
if (intPart.contains(QRegularExpression("^0{1,3}$"))) {
intPart = QString("0");
} else if (intPart.contains(QRegExp("^\\-0{0,3}$"))) {
} else if (intPart.contains(QRegularExpression("^\\-0{0,3}$"))) {
intPart = QString("-0");
}
@ -82,15 +82,15 @@ QValidator::State DoubleInputValidator::validate(QString& inputStr, int& cursorP
{
QValidator::State state = Invalid;
if (inputStr.contains(QRegExp(QString("^\\-?\\d{1,3}\\.\\d{%1}$").arg(m_decimal)))) {
if (inputStr.contains(QRegExp("^\\-?0{2,3}\\."))
if (inputStr.contains(QRegularExpression(QString("^\\-?\\d{1,3}\\.\\d{%1}$").arg(m_decimal)))) {
if (inputStr.contains(QRegularExpression("^\\-?0{2,3}\\."))
|| (inputStr.startsWith("-") && inputStr.toDouble() == 0.0)) {
state = Intermediate;
} else {
state = Acceptable;
}
} else if (inputStr.contains(QRegExp("^\\-?\\d{0,3}\\.?$"))
|| inputStr.contains(QRegExp(QString("^\\-?\\d{0,3}\\.\\d{0,%1}$").arg(m_decimal)))) {
} else if (inputStr.contains(QRegularExpression("^\\-?\\d{0,3}\\.?$"))
|| inputStr.contains(QRegularExpression(QString("^\\-?\\d{0,3}\\.\\d{0,%1}$").arg(m_decimal)))) {
state = Intermediate;
} else {
cursorPos = 0;

View File

@ -48,14 +48,14 @@ QValidator::State IntInputValidator::validate(QString& inputStr, int& cursorPos)
{
QValidator::State state = Invalid;
if (inputStr.contains(QRegExp("^\\-?\\d{1,3}$"))) {
if (inputStr.contains(QRegExp("^\\-?0{2,3}"))
if (inputStr.contains(QRegularExpression("^\\-?\\d{1,3}$"))) {
if (inputStr.contains(QRegularExpression("^\\-?0{2,3}"))
|| (inputStr.startsWith("-") && inputStr.toDouble() == 0.0)) {
state = Intermediate;
} else {
state = Acceptable;
}
} else if (inputStr.contains(QRegExp("^\\-?$"))) {
} else if (inputStr.contains(QRegularExpression("^\\-?$"))) {
state = Intermediate;
} else {
cursorPos = 0;

View File

@ -21,6 +21,7 @@
*/
#include <QDebug>
#include <QRegularExpression>
#include "libmscore/score.h"
#include "libmscore/rest.h"
@ -2156,9 +2157,8 @@ QString ExportBraille::brailleVolta(Measure* measure, Volta* volta, int staffCou
}
// 17.1.1. Page 121. Music Braille Code 2015.
const QRegExp separator("(,|\\.| )");
resetOctave(staffCount);
QStringList voltaNumbers = volta->text().split(separator);
QStringList voltaNumbers = volta->text().split(QRegularExpression("(,|\\.| )"));
QString result = QString();
for (QString voltaNumber : voltaNumbers) {
if (voltaNumber.isEmpty()) {

View File

@ -28,8 +28,8 @@
http://forums.bobdunsire.com/forums/showthread.php?t=123219
*/
#include <QtCore/QRegExp>
#include <QtCore/QtDebug>
#include <QRegularExpression>
#include <QDebug>
#include "lexer.h"
@ -366,11 +366,11 @@ void Lexer::getSym()
}while (line == "");
qDebug() << "getSym: read line" << line;
QRegExp rHeaderIgnore("^Bagpipe Reader|^MIDINoteMappings|^FrequencyMappings"
"|^InstrumentMappings|^GracenoteDurations|^FontSizes"
"|^TuneFormat");
QRegExp rTuneTempo("^TuneTempo");
if (rHeaderIgnore.indexIn(line) == 0) {
QRegularExpression rHeaderIgnore("^Bagpipe Reader|^MIDINoteMappings|^FrequencyMappings"
"|^InstrumentMappings|^GracenoteDurations|^FontSizes"
"|^TuneFormat");
QRegularExpression rTuneTempo("^TuneTempo");
if (rHeaderIgnore.match(line).capturedStart() == 0) {
type = COMMENT;
value = "";
qDebug()
@ -380,7 +380,7 @@ void Lexer::getSym()
;
line = "";
return;
} else if (rTuneTempo.indexIn(line) == 0) {
} else if (rTuneTempo.match(line).capturedStart() == 0) {
type = TEMPO;
value = line;
qDebug()
@ -401,7 +401,7 @@ void Lexer::getSym()
line = "";
} else {
// split line into space-separated words
list = line.trimmed().split(QRegExp("\\s+"));
list = line.trimmed().split(QRegularExpression("\\s+"));
qDebug()
<< "-> words"
<< list
@ -442,33 +442,33 @@ void Lexer::categorizeWord(QString word)
type = NONE;
value = word;
QRegExp rClef("&");
QRegExp rKey("sharp[cf]");
QRegExp rTSig("\\d+_(1|2|4|8|16|32)");
QRegExp rPart("I!''|I!|''!I|!I|'intro|[2-9]|'[12]|_'");
QRegExp rBar("!|!t|!!t");
QRegExp rNote("(LG|LA|[B-F]|HG|HA)[lr]?_(1|2|4|8|16|32)");
QRegExp rTie("\\^t[es]");
QRegExp rTriplet("\\^3[es]");
QRegExp rDot("'([hl][ag]|[b-f])");
QRegularExpression rClef(QRegularExpression::anchoredPattern("&"));
QRegularExpression rKey(QRegularExpression::anchoredPattern("sharp[cf]"));
QRegularExpression rTSig(QRegularExpression::anchoredPattern("\\d+_(1|2|4|8|16|32)"));
QRegularExpression rPart(QRegularExpression::anchoredPattern("I!''|I!|''!I|!I|'intro|[2-9]|'[12]|_'"));
QRegularExpression rBar(QRegularExpression::anchoredPattern("!|!t|!!t"));
QRegularExpression rNote(QRegularExpression::anchoredPattern("(LG|LA|[B-F]|HG|HA)[lr]?_(1|2|4|8|16|32)"));
QRegularExpression rTie(QRegularExpression::anchoredPattern("\\^t[es]"));
QRegularExpression rTriplet(QRegularExpression::anchoredPattern("\\^3[es]"));
QRegularExpression rDot(QRegularExpression::anchoredPattern("'([hl][ag]|[b-f])"));
if (rClef.exactMatch(word)) {
if (rClef.match(word).hasMatch()) {
type = CLEF;
} else if (rKey.exactMatch(word)) {
} else if (rKey.match(word).hasMatch()) {
type = KEY;
} else if (rTSig.exactMatch(word)) {
} else if (rTSig.match(word).hasMatch()) {
type = TSIG;
} else if (rPart.exactMatch(word)) {
} else if (rPart.match(word).hasMatch()) {
type = PART;
} else if (rBar.exactMatch(word)) {
} else if (rBar.match(word).hasMatch()) {
type = BAR;
} else if (rNote.exactMatch(word)) {
} else if (rNote.match(word).hasMatch()) {
type = NOTE;
} else if (rTie.exactMatch(word)) {
} else if (rTie.match(word).hasMatch()) {
type = TIE;
} else if (rTriplet.exactMatch(word)) {
} else if (rTriplet.match(word).hasMatch()) {
type = TRIPLET;
} else if (rDot.exactMatch(word)) {
} else if (rDot.match(word).hasMatch()) {
type = DOT;
} else if (graceMap.contains(word)) {
type = GRACE;

View File

@ -602,11 +602,12 @@ void Parser::parseNote()
{
qDebug() << "Parser::parseNote() value:" << qPrintable(lex.symValue());
QRegExp rNotes("(LG|LA|[B-F]|HG|HA)([lr]?)_(1|2|4|8|16|32)");
QRegularExpression rNotes(QRegularExpression::anchoredPattern("(LG|LA|[B-F]|HG|HA)([lr]?)_(1|2|4|8|16|32)"));
QRegularExpressionMatch rNotesMatch = rNotes.match(lex.symValue());
QStringList caps;
if (rNotes.exactMatch(lex.symValue())) {
caps = rNotes.capturedTexts();
if (rNotesMatch.hasMatch()) {
caps = rNotesMatch.capturedTexts();
qDebug() << " match" << caps.size();
if (caps.size() == 4) {
qDebug()
@ -845,10 +846,11 @@ void Parser::parseString()
{
qDebug() << "Parser::parseString() value:" << qPrintable(lex.symValue());
QRegExp rString("\\\"(.*)\\\",\\(([A-Z]),.*\\)");
QRegularExpression rString(QRegularExpression::anchoredPattern("\\\"(.*)\\\",\\(([A-Z]),.*\\)"));
QRegularExpressionMatch rStringMatch = rString.match(lex.symValue());
if (rString.exactMatch(lex.symValue())) {
QStringList caps = rString.capturedTexts();
if (rStringMatch.hasMatch()) {
QStringList caps = rStringMatch.capturedTexts();
if (caps.size() == 3) {
if (caps.at(2) == "T") {
title = caps.at(1);
@ -875,10 +877,11 @@ void Parser::parseTempo()
{
qDebug() << "Parser::parseTempo() value:" << qPrintable(lex.symValue());
QRegExp rTempo("^TuneTempo,(\\d+)");
QRegularExpression rTempo(QRegularExpression::anchoredPattern("^TuneTempo,(\\d+)"));
QRegularExpressionMatch rTempoMatch = rTempo.match(lex.symValue());
if (rTempo.exactMatch(lex.symValue())) {
QStringList caps = rTempo.capturedTexts();
if (rTempoMatch.hasMatch()) {
QStringList caps = rTempoMatch.capturedTexts();
if (caps.size() == 2) {
tempo = caps.at(1).toInt();
}
@ -894,10 +897,11 @@ void Parser::parseTSig()
{
qDebug() << "Parser::parseTSig() value:" << qPrintable(lex.symValue());
QRegExp rTSig("(\\d+)_(1|2|4|8|16|32)");
QRegularExpression rTSig(QRegularExpression::anchoredPattern("(\\d+)_(1|2|4|8|16|32)"));
QRegularExpressionMatch rTSigMatch = rTSig.match(lex.symValue());
if (rTSig.exactMatch(lex.symValue())) {
QStringList caps = rTSig.capturedTexts();
if (rTSigMatch.hasMatch()) {
QStringList caps = rTSigMatch.capturedTexts();
if (caps.size() == 3) {
beats = caps.at(1).toInt();
beat = caps.at(2).toInt();

View File

@ -28,6 +28,7 @@
#include <assert.h>
#include <cmath>
#include <QRegularExpression>
#include "libmscore/score.h"
#include "thirdparty/qzip/qzipreader_p.h"
@ -426,9 +427,10 @@ void ChordObj::readCapx(XmlReader& e)
static signed char pitchStr2Char(QString& strPitch)
{
QRegExp pitchRegExp("[A-G][0-9]");
QRegularExpression pitchRegex(QRegularExpression::anchoredPattern("[A-G][0-9]"));
QRegularExpressionMatch match = pitchRegex.match(strPitch);
if (!pitchRegExp.exactMatch(strPitch)) {
if (!match.hasMatch()) {
qDebug("pitchStr2Char: illegal pitch '%s'", qPrintable(strPitch));
return 0;
}

View File

@ -25,6 +25,7 @@
#include <cmath>
#include <QTextCodec>
#include <QDebug>
#include <QRegularExpression>
#include "importptb.h"
@ -770,8 +771,8 @@ void GuitarPro::readLyrics()
gpLyrics.beatCounter = 0;
QString lyrics = readWordPascalString();
lyrics.replace(QRegExp("\n"), " ");
lyrics.replace(QRegExp("\r"), " ");
lyrics.replace(QRegularExpression("\n"), " ");
lyrics.replace(QRegularExpression("\r"), " ");
auto sl = lyrics.split(" ", Qt::KeepEmptyParts);
//gpLyrics.lyrics = lyrics.split(" ", Qt::KeepEmptyParts);
for (auto& str : sl) {

View File

@ -42,6 +42,7 @@
#include <math.h>
#include <QBuffer>
#include <QDate>
#include <QRegularExpression>
#include "config.h"
@ -2056,8 +2057,8 @@ void ExportMusicXml::timesig(TimeSig* tsig)
tagName += color2xml(tsig);
_xml.stag(tagName);
QRegExp rx("^\\d+(\\+\\d+)+$"); // matches a compound numerator
if (rx.exactMatch(ns)) {
QRegularExpression regex(QRegularExpression::anchoredPattern("^\\d+(\\+\\d+)+$")); // matches a compound numerator
if (regex.match(ns).hasMatch()) {
// if compound numerator, exported as is
_xml.tag("beats", ns);
} else {
@ -4033,10 +4034,11 @@ static bool findMetronome(const QList<TextFragment>& list,
// find first note, limiting search to the part left of the first '=',
// to prevent matching the second note in a "note1 = note2" metronome
int pos1 = TempoText::findTempoDuration(words.left(indEq), len1, dur);
QRegExp eq("\\s*=\\s*");
int pos2 = eq.indexIn(words, pos1 + len1);
QRegularExpression equationRegEx("\\s*=\\s*");
QRegularExpressionMatch equationMatch;
int pos2 = words.indexOf(equationRegEx, pos1 + len1, &equationMatch);
if (pos1 != -1 && pos2 == pos1 + len1) {
int len2 = eq.matchedLength();
int len2 = equationMatch.capturedLength();
if (words.length() > pos2 + len2) {
QString s1 = words.mid(0, pos1); // string to the left of metronome
QString s2 = words.mid(pos1, len1); // first note
@ -4054,13 +4056,14 @@ static bool findMetronome(const QList<TextFragment>& list,
// now determine what is to the right of the equals sign
// must have either a (dotted) note or a number at start of s4
int len3 = 0;
QRegExp nmb("\\d+");
QRegularExpression numberRegEx("\\d+");
int pos3 = TempoText::findTempoDuration(s4, len3, dur);
if (pos3 == -1) {
// did not find note, try to find a number
pos3 = nmb.indexIn(s4);
QRegularExpressionMatch numberMatch;
pos3 = s4.indexOf(numberRegEx, 0, &numberMatch);
if (pos3 == 0) {
len3 = nmb.matchedLength();
len3 = numberMatch.capturedLength();
}
}
if (pos3 == -1) {

View File

@ -20,6 +20,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QRegularExpression>
#include "libmscore/box.h"
#include "libmscore/chordrest.h"
#include "libmscore/instrtemplate.h"
@ -1255,13 +1257,13 @@ static QString text2syms(const QString& t)
static QString decodeEntities(const QString& src)
{
QString ret(src);
QRegExp re("&#([0-9]+);");
re.setMinimal(true);
QRegularExpression re("&#([0-9]+);", QRegularExpression::InvertedGreedinessOption);
int pos = 0;
while ((pos = re.indexIn(src, pos)) != -1) {
ret = ret.replace(re.cap(0), QChar(re.cap(1).toInt(0, 10)));
pos += re.matchedLength();
QRegularExpressionMatch match;
while ((pos = src.indexOf(re, pos, &match)) != -1) {
ret = ret.replace(match.capturedTexts()[0], QChar(match.capturedTexts()[1].toInt(0, 10)));
pos += match.capturedLength();
}
return ret;
}

View File

@ -713,13 +713,13 @@ namespace xmlpass2 {
static QString decodeEntities(const QString& src)
{
QString ret(src);
QRegExp re("&#([0-9]+);");
re.setMinimal(true);
QRegularExpression re("&#([0-9]+);", QRegularExpression::InvertedGreedinessOption);
int pos = 0;
while ((pos = re.indexIn(src, pos)) != -1) {
ret = ret.replace(re.cap(0), QChar(re.cap(1).toInt(0, 10)));
pos += re.matchedLength();
QRegularExpressionMatch match;
while ((pos = src.indexOf(re, pos, &match)) != -1) {
ret = ret.replace(match.capturedTexts()[0], QChar(match.capturedTexts()[1].toInt(0, 10)));
pos += match.capturedLength();
}
return ret;
}
@ -2835,36 +2835,36 @@ void MusicXMLParserDirection::dynamics()
static QString matchRepeat(const QString& lowerTxt)
{
QString repeat;
QRegExp daCapo("d\\.? *c\\.?|da *capo");
QRegExp daCapoAlFine("d\\.? *c\\.? *al *fine|da *capo *al *fine");
QRegExp daCapoAlCoda("d\\.? *c\\.? *al *coda|da *capo *al *coda");
QRegExp dalSegno("d\\.? *s\\.?|d[ae]l *segno");
QRegExp dalSegnoAlFine("d\\.? *s\\.? *al *fine|d[ae]l *segno *al *fine");
QRegExp dalSegnoAlCoda("d\\.? *s\\.? *al *coda|d[ae]l *segno *al *coda");
QRegExp fine("fine");
QRegExp toCoda("to *coda");
if (daCapo.exactMatch(lowerTxt)) {
QRegularExpression daCapo(QRegularExpression::anchoredPattern("d\\.? *c\\.?|da *capo"));
QRegularExpression daCapoAlFine(QRegularExpression::anchoredPattern("d\\.? *c\\.? *al *fine|da *capo *al *fine"));
QRegularExpression daCapoAlCoda(QRegularExpression::anchoredPattern("d\\.? *c\\.? *al *coda|da *capo *al *coda"));
QRegularExpression dalSegno(QRegularExpression::anchoredPattern("d\\.? *s\\.?|d[ae]l *segno"));
QRegularExpression dalSegnoAlFine(QRegularExpression::anchoredPattern("d\\.? *s\\.? *al *fine|d[ae]l *segno *al *fine"));
QRegularExpression dalSegnoAlCoda(QRegularExpression::anchoredPattern("d\\.? *s\\.? *al *coda|d[ae]l *segno *al *coda"));
QRegularExpression fine(QRegularExpression::anchoredPattern("fine"));
QRegularExpression toCoda(QRegularExpression::anchoredPattern("to *coda"));
if (daCapo.match(lowerTxt).hasMatch()) {
repeat = "daCapo";
}
if (daCapoAlFine.exactMatch(lowerTxt)) {
if (daCapoAlFine.match(lowerTxt).hasMatch()) {
repeat = "daCapoAlFine";
}
if (daCapoAlCoda.exactMatch(lowerTxt)) {
if (daCapoAlCoda.match(lowerTxt).hasMatch()) {
repeat = "daCapoAlCoda";
}
if (dalSegno.exactMatch(lowerTxt)) {
if (dalSegno.match(lowerTxt).hasMatch()) {
repeat = "dalSegno";
}
if (dalSegnoAlFine.exactMatch(lowerTxt)) {
if (dalSegnoAlFine.match(lowerTxt).hasMatch()) {
repeat = "dalSegnoAlFine";
}
if (dalSegnoAlCoda.exactMatch(lowerTxt)) {
if (dalSegnoAlCoda.match(lowerTxt).hasMatch()) {
repeat = "dalSegnoAlCoda";
}
if (fine.exactMatch(lowerTxt)) {
if (fine.match(lowerTxt).hasMatch()) {
repeat = "fine";
}
if (toCoda.exactMatch(lowerTxt)) {
if (toCoda.match(lowerTxt).hasMatch()) {
repeat = "toCoda";
}
return repeat;

View File

@ -100,7 +100,7 @@ public:
int mscoreVersion() const { return Ms::version(); }
int mscoreMajorVersion() const { return majorVersion(); }
int mscoreMinorVersion() const { return minorVersion(); }
int mscoreUpdateVersion() const { return updateVersion(); }
int mscoreUpdateVersion() const { return patchVersion(); }
qreal mscoreDPI() const { return DPI; }
};
} // namespace Ms