Skip to content

Commit

Permalink
Use QRegExp for Qt < 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Busemann authored and j2doll committed Oct 8, 2019
1 parent 5dd8b17 commit 0a7bf28
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions QXlsx/header/xlsxworksheet_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
#include <QVector>
#include <QImage>
#include <QSharedPointer>
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
#include <QRegularExpression>
#else
#include <QRegExp>
#endif

#include "xlsxworksheet.h"
#include "xlsxabstractsheet_p.h"
Expand Down Expand Up @@ -277,7 +281,11 @@ class WorksheetPrivate : public AbstractSheetPrivate
bool showOutlineSymbols;
bool showWhiteSpace;

#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
QRegularExpression urlPattern;
#else
QRegExp urlPattern;
#endif

private:

Expand Down
16 changes: 16 additions & 0 deletions QXlsx/source/xlsxcellreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#include "xlsxcellreference.h"
#include <QStringList>
#include <QMap>

#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
#include <QRegularExpression>
#else
#include <QRegExp>
#endif

QT_BEGIN_NAMESPACE_XLSX

Expand Down Expand Up @@ -118,6 +123,7 @@ CellReference::CellReference(const char *cell)

void CellReference::init(const QString &cell_str)
{
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
static QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));
QRegularExpressionMatch match = re.match(cell_str);
if (match.hasMatch()) {
Expand All @@ -126,6 +132,16 @@ void CellReference::init(const QString &cell_str)
_row = row_str.toInt();
_column = col_from_name(col_str);
}
#else
QRegExp re(QLatin1String("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));
if (re.indexIn(cell_str) != -1)
{
const QString col_str = re.cap(1);
const QString row_str = re.cap(2);
_row = row_str.toInt();
_column = col_from_name(col_str);
}
#endif
}

/*!
Expand Down
14 changes: 14 additions & 0 deletions QXlsx/source/xlsxutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

#include <QString>
#include <QPoint>
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
#include <QRegularExpression>
#else
#include <QRegExp>
#endif
#include <QMap>
#include <QStringList>
#include <QColor>
Expand Down Expand Up @@ -166,8 +170,13 @@ QString createSafeSheetName(const QString &nameProposal)
ret = unescapeSheetName(ret);

//Replace invalid chars with space.
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
if (nameProposal.contains(QRegularExpression(QStringLiteral("[/\\\\?*\\][:]"))))
ret.replace(QRegularExpression(QStringLiteral("[/\\\\?*\\][:]")), QStringLiteral(" "));
#else
if (nameProposal.contains(QRegExp(QLatin1String("[/\\\\?*\\][:]"))))
ret.replace(QRegExp(QLatin1String("[/\\\\?*\\][:]")), QLatin1String(" "));
#endif
if (ret.startsWith(QLatin1Char('\'')))
ret[0] = QLatin1Char(' ');
if (ret.endsWith(QLatin1Char('\'')))
Expand All @@ -187,8 +196,13 @@ QString escapeSheetName(const QString &sheetName)
Q_ASSERT(!sheetName.startsWith(QLatin1Char('\'')) && !sheetName.endsWith(QLatin1Char('\'')));

//These is no need to escape
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
if (!sheetName.contains(QRegularExpression(QStringLiteral("[ +\\-,%^=<>'&]"))))
return sheetName;
#else
if (!sheetName.contains(QRegExp(QLatin1String("[ +\\-,%^=<>'&]"))))
return sheetName;
#endif

//OK, escape is needed.
QString name = sheetName;
Expand Down
1 change: 0 additions & 1 deletion QXlsx/source/xlsxworksheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <QPoint>
#include <QFile>
#include <QUrl>
#include <QRegularExpression>
#include <QDebug>
#include <QBuffer>
#include <QXmlStreamWriter>
Expand Down

0 comments on commit 0a7bf28

Please sign in to comment.