summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qregularexpression.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-07-05 19:01:08 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-07-29 23:04:27 +0200
commite540d4a8647c41a3e710a555f5dcc44edb7dfcb4 (patch)
tree25c6441166d1647b95e8983ac48a2204e3390fe4 /src/corelib/text/qregularexpression.h
parent8d6b274fa4c65e87443c0fbf8425229230385405 (diff)
QRegularExpression: introduce (global)matchView
QRegularExpression::match (and globalMatch) is currently overloaded for QString and QStringView. This creates a subtle API asymmetry: QRegularExpression re; auto m1 = re.match(getQString()); // OK auto m2 = re.match(getStdU16String()); // Dangling This goes against our decision that every time that there's a possible lifetime issue at play, it should be "evident". Solving the lifetime issue here is possible, but tricky -- since QRegularExpression is out-of-line, one needs a type-erased container for the input string (basically, std::any) to keep it alive and so on. Instead I went for the simpler solution: deprecate match(QStringView) and introduce matchView(QStringView) (same for globalMatch). This makes it clear that the call is matching over a view and therefore users are supposed to keep the source object alive. Drive-by, remove the documentation that says that the QString overloads might not keep the string alive: they do and forever will. [ChangeLog][QtCore][QRegularExpression] Added the matchView() and globalMatchView() functions that operate on string views. The match(QStringView) and globalMatch(QStringView) overloads have been deprecated. Change-Id: I054b8605c2fdea59b556dcfea8920ef4eee78ee9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qregularexpression.h')
-rw-r--r--src/corelib/text/qregularexpression.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h
index 9b7de26d07..fc0f1302e3 100644
--- a/src/corelib/text/qregularexpression.h
+++ b/src/corelib/text/qregularexpression.h
@@ -91,11 +91,20 @@ public:
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+#if QT_DEPRECATED_SINCE(6, 8)
[[nodiscard]]
+ QT_DEPRECATED_VERSION_X_6_8("Use matchView instead.")
QRegularExpressionMatch match(QStringView subjectView,
qsizetype offset = 0,
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+#endif
+
+ [[nodiscard]]
+ QRegularExpressionMatch matchView(QStringView subjectView,
+ qsizetype offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
[[nodiscard]]
QRegularExpressionMatchIterator globalMatch(const QString &subject,
@@ -103,11 +112,20 @@ public:
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+#if QT_DEPRECATED_SINCE(6, 8)
[[nodiscard]]
+ QT_DEPRECATED_VERSION_X_6_8("Use globalMatchView instead.")
QRegularExpressionMatchIterator globalMatch(QStringView subjectView,
qsizetype offset = 0,
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+#endif
+
+ [[nodiscard]]
+ QRegularExpressionMatchIterator globalMatchView(QStringView subjectView,
+ qsizetype offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
void optimize() const;