From 0a7bf28e7e8606648f56b86675d828face6ef9c7 Mon Sep 17 00:00:00 2001 From: Marco Busemann Date: Fri, 4 Oct 2019 08:57:29 +0200 Subject: [PATCH] Use QRegExp for Qt < 5 --- QXlsx/header/xlsxworksheet_p.h | 8 ++++++++ QXlsx/source/xlsxcellreference.cpp | 16 ++++++++++++++++ QXlsx/source/xlsxutility.cpp | 14 ++++++++++++++ QXlsx/source/xlsxworksheet.cpp | 1 - 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/QXlsx/header/xlsxworksheet_p.h b/QXlsx/header/xlsxworksheet_p.h index a1a88a3b..5160f1f3 100644 --- a/QXlsx/header/xlsxworksheet_p.h +++ b/QXlsx/header/xlsxworksheet_p.h @@ -42,7 +42,11 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) #include +#else +#include +#endif #include "xlsxworksheet.h" #include "xlsxabstractsheet_p.h" @@ -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: diff --git a/QXlsx/source/xlsxcellreference.cpp b/QXlsx/source/xlsxcellreference.cpp index e7cf5da9..86301d06 100644 --- a/QXlsx/source/xlsxcellreference.cpp +++ b/QXlsx/source/xlsxcellreference.cpp @@ -25,7 +25,12 @@ #include "xlsxcellreference.h" #include #include + +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) #include +#else +#include +#endif QT_BEGIN_NAMESPACE_XLSX @@ -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()) { @@ -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 } /*! diff --git a/QXlsx/source/xlsxutility.cpp b/QXlsx/source/xlsxutility.cpp index 3745c543..02d1a46f 100644 --- a/QXlsx/source/xlsxutility.cpp +++ b/QXlsx/source/xlsxutility.cpp @@ -27,7 +27,11 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) #include +#else +#include +#endif #include #include #include @@ -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('\''))) @@ -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; diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index c3308da9..09680ea6 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include