summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-05-11 15:49:19 +0200
committerMarc Mutz <marc.mutz@kdab.com>2020-05-13 08:04:40 +0200
commitb49314af1d4125205611f6037539f4c8f372b909 (patch)
tree6741111fbdb87872abd3f6868a3a2cb33ef38d7b /src/corelib/io
parent554ef6c39ca3863049de4988fe33f327e72dbe7e (diff)
Port qt_check_std3rules() to QStringView
Also port its callees. These functions scream to the QStringView-ified... Change-Id: I13c95d65941eb8d02223306d80efd1437b4bd9b7 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qurl_p.h2
-rw-r--r--src/corelib/io/qurlidna.cpp26
2 files changed, 15 insertions, 13 deletions
diff --git a/src/corelib/io/qurl_p.h b/src/corelib/io/qurl_p.h
index c5379ab700..c352399505 100644
--- a/src/corelib/io/qurl_p.h
+++ b/src/corelib/io/qurl_p.h
@@ -67,7 +67,7 @@ enum AceLeadingDot { AllowLeadingDot, ForbidLeadingDot };
enum AceOperation { ToAceOnly, NormalizeAce };
extern QString qt_ACE_do(QStringView domain, AceOperation op, AceLeadingDot dot);
extern Q_AUTOTEST_EXPORT bool qt_nameprep(QString *source, int from);
-extern Q_AUTOTEST_EXPORT bool qt_check_std3rules(const QChar *uc, int len);
+extern Q_AUTOTEST_EXPORT bool qt_check_std3rules(QStringView in);
extern Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString *output);
extern Q_AUTOTEST_EXPORT QString qt_punycodeDecoder(const QString &pc);
extern Q_AUTOTEST_EXPORT QString qt_urlRecodeByteArray(const QByteArray &ba);
diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp
index 49d84c2dbf..b06ab08910 100644
--- a/src/corelib/io/qurlidna.cpp
+++ b/src/corelib/io/qurlidna.cpp
@@ -2119,13 +2119,16 @@ Q_AUTOTEST_EXPORT bool qt_nameprep(QString *source, int from)
return true;
}
-static const QChar *qt_find_nonstd3(const QChar *uc, int len, Qt::CaseSensitivity cs)
+static const QChar *qt_find_nonstd3(QStringView in, Qt::CaseSensitivity cs)
{
+ const QChar * const uc = in.data();
+ const qsizetype len = in.size();
+
if (len > 63)
return uc;
- for (int i = 0; i < len; ++i) {
- ushort c = uc[i].unicode();
+ for (qsizetype i = 0; i < len; ++i) {
+ const char16_t c = uc[i].unicode();
if (c == '-' && (i == 0 || i == len - 1))
return uc + i;
@@ -2145,22 +2148,21 @@ static const QChar *qt_find_nonstd3(const QChar *uc, int len, Qt::CaseSensitivit
return nullptr;
}
-Q_AUTOTEST_EXPORT bool qt_check_std3rules(const QChar *uc, int len)
+Q_AUTOTEST_EXPORT bool qt_check_std3rules(QStringView in)
{
- return qt_find_nonstd3(uc, len, Qt::CaseInsensitive) == nullptr;
+ return qt_find_nonstd3(in, Qt::CaseInsensitive) == nullptr;
}
-static bool qt_check_nameprepped_std3(const QChar *in, int len)
+static bool qt_check_nameprepped_std3(QStringView in)
{
// fast path: check for lowercase ASCII
- const QChar *firstNonAscii = qt_find_nonstd3(in, len, Qt::CaseSensitive);
+ const QChar *firstNonAscii = qt_find_nonstd3(in, Qt::CaseSensitive);
if (firstNonAscii == nullptr) {
// everything was lowercase ASCII, digits or hyphen
return true;
}
- const QChar *e = in + len;
- QString origin = QString::fromRawData(firstNonAscii, e - firstNonAscii);
+ QString origin = QString::fromRawData(firstNonAscii, in.end() - firstNonAscii);
QString copy = origin;
qt_nameprep(&copy, 0);
return origin == copy;
@@ -2548,7 +2550,7 @@ QString qt_ACE_do(QStringView domain, AceOperation op, AceLeadingDot dot)
if (simple) {
// fastest case: this is the common case (non IDN-domains)
// so we're done
- if (!qt_check_std3rules(result.constData() + prevLen, labelLength))
+ if (!qt_check_std3rules(QStringView{result.constData() + prevLen, labelLength}))
return QString();
} else {
// Punycode encoding and decoding cannot be done in-place
@@ -2567,7 +2569,7 @@ QString qt_ACE_do(QStringView domain, AceOperation op, AceLeadingDot dot)
QString tmp = qt_punycodeDecoder(aceForm);
if (tmp.isEmpty())
return QString(); // shouldn't happen, since we've just punycode-encoded it
- if (qt_check_nameprepped_std3(tmp.constData(), tmp.size())) {
+ if (qt_check_nameprepped_std3(tmp)) {
result.resize(prevLen + tmp.size());
memcpy(result.data() + prevLen, tmp.constData(), tmp.size() * sizeof(QChar));
appended = true;
@@ -2579,7 +2581,7 @@ QString qt_ACE_do(QStringView domain, AceOperation op, AceLeadingDot dot)
memcpy(result.data() + prevLen, aceForm.constData(), aceForm.size() * sizeof(QChar));
}
- if (!qt_check_std3rules(aceForm.constData(), aceForm.size()))
+ if (!qt_check_std3rules(aceForm))
return QString();
}