diff --git a/avogadro/qtplugins/coordinateeditor/coordinateeditordialog.cpp b/avogadro/qtplugins/coordinateeditor/coordinateeditordialog.cpp index 7928ce451a..84391dd5ab 100644 --- a/avogadro/qtplugins/coordinateeditor/coordinateeditordialog.cpp +++ b/avogadro/qtplugins/coordinateeditor/coordinateeditordialog.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -77,18 +77,19 @@ enum TokenType }; // Some frequently used regexes: -static const QRegExp TOKEN_SEPARATOR("[\\s,;]+"); -static const QRegExp VALID_TOKEN("[^\\s,;]+"); -static const QRegExp INT_CHECKER("(:?[+-])?\\d+"); -static const QRegExp DOUBLE_CHECKER("(:?[+-])?" // Leading sign - "(:?" // Must match one of the following: - "\\d*\\.\\d*" // Fractional part - "|" // or - "\\d+[Ee](:?[+-])?\\d+" // Exponential part - "|" // or - "\\d*\\.\\d*" // Fractional part and - "[Ee](:?[+-])?\\d+" // Exponential part - ")"); +static const QRegularExpression TOKEN_SEPARATOR("[\\s,;]+"); +static const QRegularExpression VALID_TOKEN("[^\\s,;]+"); +// These two need to be exact +static const QRegularExpression INT_CHECKER(QRegularExpression::anchoredPattern("(:?[+-])?\\d+")); +static const QRegularExpression DOUBLE_CHECKER(QRegularExpression::anchoredPattern("(:?[+-])?" // Leading sign + "(:?" // Must match one of the following: + "\\d*\\.\\d*" // Fractional part + "|" // or + "\\d+[Ee](:?[+-])?\\d+" // Exponential part + "|" // or + "\\d*\\.\\d*" // Fractional part and + "[Ee](:?[+-])?\\d+" // Exponential part + ")")); struct AtomStruct { @@ -140,8 +141,8 @@ CoordinateEditorDialog::CoordinateEditorDialog(QWidget* parent_) SLOT(textModified(bool))); // Setup spec edit - QRegExp specRegExp("[#ZGSLNabcxyz01_]*"); - auto* specValidator = new QRegExpValidator(specRegExp, this); + QRegularExpression specRegExp("[#ZGSLNabcxyz01_]*"); + auto* specValidator = new QRegularExpressionValidator(specRegExp, this); m_ui->spec->setValidator(specValidator); connect(m_ui->presets, SIGNAL(currentIndexChanged(int)), SLOT(presetChanged(int))); @@ -392,13 +393,14 @@ void CoordinateEditorDialog::validateInputWorker() cleanToken.replace(0, 1, cleanToken[0].toUpper()); // Split the label into symbol and number - QRegExp labelSplitter("([A-Z][a-z]?)(\\d+)"); - if (labelSplitter.indexIn(cleanToken) == -1) { + QRegularExpression labelSplitter("([A-Z][a-z]?)(\\d+)"); + QRegularExpressionMatch match = labelSplitter.match(cleanToken); + if (match.hasMatch()) { m_ui->text->markInvalid(tokenCursor, tr("Invalid atom label.")); break; } // check the symbol - std::string tokenStd(labelSplitter.cap(1).toStdString()); + std::string tokenStd(match.captured(1).toStdString()); atom.atomicNumber = Elements::atomicNumberFromSymbol(tokenStd); if (atom.atomicNumber == Avogadro::InvalidElement) m_ui->text->markInvalid(tokenCursor, tr("Invalid element symbol.")); @@ -682,9 +684,9 @@ QString CoordinateEditorDialog::detectInputFormat() const foreach (const QString& token, tokens) { TokenType tokenType = String; - if (INT_CHECKER.exactMatch(token)) + if (INT_CHECKER.match(token).hasMatch()) tokenType = Integer; - else if (DOUBLE_CHECKER.exactMatch(token)) + else if (DOUBLE_CHECKER.match(token).hasMatch()) tokenType = Double; ++tokenTypeCounts[tokenType]; tokenTypes << tokenType; @@ -797,8 +799,8 @@ QString CoordinateEditorDialog::detectInputFormat() const // Check the current specification -- if a|b|c appears before x|y|z, assume // that the specified coordinates are lattice coords - static QRegExp cartesianSniffer("x|y|z"); - static QRegExp fractionalSniffer("a|b|c"); + static QRegularExpression cartesianSniffer("x|y|z"); + static QRegularExpression fractionalSniffer("a|b|c"); const QString currentSpec(m_ui->spec->text()); int cartesianIndex = currentSpec.indexOf(cartesianSniffer); int fractionalIndex = currentSpec.indexOf(fractionalSniffer);