summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-07-01 20:05:36 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-02-22 21:15:31 +0100
commit8123a69e6edcd7080652489e8e758406a7a0e378 (patch)
tree1b24d7336a919e621c108d6d42fdd2b108f62865 /src/corelib/text/qstring.cpp
parentb727f2190fb4878aad5edf1536e875e1b75907ae (diff)
QRegularExpression: print the pattern when warning
Just as a minor debugging helper: when warning that an invalid regular expression object is being used to match, also print the used regular expression pattern. Change-Id: I0f99bcf4ca87ec67d04ed91d9dc315814f56d392 Fixes: QTBUG-76670 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r--src/corelib/text/qstring.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 72c839a478..f1ee16901b 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -1641,6 +1641,10 @@ static int qArgDigitValue(QChar ch) noexcept
return -1;
}
+#if QT_CONFIG(regularexpression)
+Q_DECL_COLD_FUNCTION
+void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *where);
+#endif
/*!
\macro QT_RESTRICTED_CAST_FROM_ASCII
@@ -4347,7 +4351,7 @@ Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE);
QString &QString::replace(const QRegularExpression &re, const QString &after)
{
if (!re.isValid()) {
- qWarning("QString::replace: invalid QRegularExpression object");
+ qtWarnAboutInvalidRegularExpression(re.pattern(), "QString::replace");
return *this;
}
@@ -4873,7 +4877,7 @@ static QString extractSections(const QList<qt_section_chunk> &sections, qsizetyp
QString QString::section(const QRegularExpression &re, qsizetype start, qsizetype end, SectionFlags flags) const
{
if (!re.isValid()) {
- qWarning("QString::section: invalid QRegularExpression object");
+ qtWarnAboutInvalidRegularExpression(re.pattern(), "QString::section");
return QString();
}
@@ -7682,7 +7686,7 @@ static ResultList splitString(const String &source, const QRegularExpression &re
{
ResultList list;
if (!re.isValid()) {
- qWarning("QString::split: invalid QRegularExpression object");
+ qtWarnAboutInvalidRegularExpression(re.pattern(), "QString::split");
return list;
}
@@ -10584,7 +10588,7 @@ qsizetype QtPrivate::lastIndexOf(QLatin1String haystack, qsizetype from, QLatin1
qsizetype QtPrivate::indexOf(QStringView haystack, const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
{
if (!re.isValid()) {
- qWarning("QString(View)::indexOf: invalid QRegularExpression object");
+ qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::indexOf");
return -1;
}
@@ -10602,7 +10606,7 @@ qsizetype QtPrivate::indexOf(QStringView haystack, const QRegularExpression &re,
qsizetype QtPrivate::lastIndexOf(QStringView haystack, const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
{
if (!re.isValid()) {
- qWarning("QString(View)::lastIndexOf: invalid QRegularExpression object");
+ qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::lastIndexOf");
return -1;
}
@@ -10627,7 +10631,7 @@ qsizetype QtPrivate::lastIndexOf(QStringView haystack, const QRegularExpression
bool QtPrivate::contains(QStringView haystack, const QRegularExpression &re, QRegularExpressionMatch *rmatch)
{
if (!re.isValid()) {
- qWarning("QString(View)::contains: invalid QRegularExpression object");
+ qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::contains");
return false;
}
QRegularExpressionMatch m = re.match(haystack);
@@ -10640,7 +10644,7 @@ bool QtPrivate::contains(QStringView haystack, const QRegularExpression &re, QRe
qsizetype QtPrivate::count(QStringView haystack, const QRegularExpression &re)
{
if (!re.isValid()) {
- qWarning("QString(View)::count: invalid QRegularExpression object");
+ qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::count");
return 0;
}
qsizetype count = 0;