summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-05-12 08:41:07 +0200
committerMarc Mutz <marc.mutz@kdab.com>2020-05-13 13:22:09 +0000
commita504f63f2ebd3aa62a7d1c4087a0620b1c38758b (patch)
tree240001fc7ced761418b47e4b14f8e6acf51d9b15 /src/corelib/io
parente201d585401ea4affe8dde3f4f43f15bf49fa229 (diff)
Port qt_punycodeEncoder() to QStringView
Change-Id: I264e67bc08413f8a39e2d16c774bfd2c76c320ac 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.cpp28
2 files changed, 14 insertions, 16 deletions
diff --git a/src/corelib/io/qurl_p.h b/src/corelib/io/qurl_p.h
index c352399505..9a063a37e6 100644
--- a/src/corelib/io/qurl_p.h
+++ b/src/corelib/io/qurl_p.h
@@ -68,7 +68,7 @@ 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(QStringView in);
-extern Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString *output);
+extern Q_AUTOTEST_EXPORT void qt_punycodeEncoder(QStringView in, 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 b06ab08910..08c5d1759c 100644
--- a/src/corelib/io/qurlidna.cpp
+++ b/src/corelib/io/qurlidna.cpp
@@ -2209,21 +2209,21 @@ static inline void appendEncode(QString* output, uint& delta, uint& bias, uint&
++h;
}
-Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString *output)
+Q_AUTOTEST_EXPORT void qt_punycodeEncoder(QStringView in, QString *output)
{
uint n = initial_n;
uint delta = 0;
uint bias = initial_bias;
int outLen = output->length();
- output->resize(outLen + ucLength);
+ output->resize(outLen + in.length());
QChar *d = output->data() + outLen;
bool skipped = false;
// copy all basic code points verbatim to output.
- for (uint j = 0; j < (uint) ucLength; ++j) {
- if (s[j].unicode() < 0x80)
- *d++ = s[j];
+ for (QChar c : in) {
+ if (c.unicode() < 0x80)
+ *d++ = c;
else
skipped = true;
}
@@ -2246,14 +2246,13 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString
// while there are still unprocessed non-basic code points left in
// the input string...
- while (h < (uint) ucLength) {
+ while (h < (uint) in.length()) {
// find the character in the input string with the lowest
// unicode value.
uint m = Q_MAXINT;
- uint j;
- for (j = 0; j < (uint) ucLength; ++j) {
- if (s[j].unicode() >= n && s[j].unicode() < m)
- m = (uint) s[j].unicode();
+ for (QChar c : in) {
+ if (c.unicode() >= n && c.unicode() < m)
+ m = (uint) c.unicode();
}
// reject out-of-bounds unicode characters
@@ -2265,12 +2264,11 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString
delta += (m - n) * (h + 1);
n = m;
- // for each code point in the input string
- for (j = 0; j < (uint) ucLength; ++j) {
+ for (QChar c : in) {
// increase delta until we reach the character with the
// lowest unicode code. fail if delta overflows.
- if (s[j].unicode() < n) {
+ if (c.unicode() < n) {
++delta;
if (!delta) {
output->truncate(outLen);
@@ -2280,7 +2278,7 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString
// if j is the index of the character with the lowest
// unicode code...
- if (s[j].unicode() == n) {
+ if (c.unicode() == n) {
appendEncode(output, delta, bias, b, h);
}
}
@@ -2561,7 +2559,7 @@ QString qt_ACE_do(QStringView domain, AceOperation op, AceLeadingDot dot)
aceForm.resize(0);
if (toReserve > aceForm.capacity())
aceForm.reserve(toReserve);
- qt_punycodeEncoder(result.constData() + prevLen, result.size() - prevLen, &aceForm);
+ qt_punycodeEncoder(QStringView{result}.mid(prevLen), &aceForm);
// We use resize()+memcpy() here because we're overwriting the data we've copied
bool appended = false;