Port qt_urlRecode() to QStringView
It's about time :) Change-Id: I27e597516318382850d4c193fd5b66a35fb9c316 Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
cf52a36994
commit
548dcef089
|
|
@ -825,7 +825,7 @@ recodeFromUser(const QString &input, const ushort *actions, int from, int to)
|
|||
QString output;
|
||||
const QChar *begin = input.constData() + from;
|
||||
const QChar *end = input.constData() + to;
|
||||
if (qt_urlRecode(output, begin, end, {}, actions))
|
||||
if (qt_urlRecode(output, QStringView{begin, end}, {}, actions))
|
||||
return output;
|
||||
|
||||
return input.mid(from, to - from);
|
||||
|
|
@ -833,7 +833,7 @@ recodeFromUser(const QString &input, const ushort *actions, int from, int to)
|
|||
|
||||
// appendXXXX functions: copy from the internal form to the external, user form.
|
||||
// the internal value is stored in its PrettyDecoded form, so that case is easy.
|
||||
static inline void appendToUser(QString &appendTo, const QStringRef &value, QUrl::FormattingOptions options,
|
||||
static inline void appendToUser(QString &appendTo, QStringView value, QUrl::FormattingOptions options,
|
||||
const ushort *actions)
|
||||
{
|
||||
if (options == QUrl::PrettyDecoded) {
|
||||
|
|
@ -841,17 +841,10 @@ static inline void appendToUser(QString &appendTo, const QStringRef &value, QUrl
|
|||
return;
|
||||
}
|
||||
|
||||
if (!qt_urlRecode(appendTo, value.data(), value.end(), options, actions))
|
||||
if (!qt_urlRecode(appendTo, value, options, actions))
|
||||
appendTo += value;
|
||||
}
|
||||
|
||||
static inline void appendToUser(QString &appendTo, const QString &value, QUrl::FormattingOptions options,
|
||||
const ushort *actions)
|
||||
{
|
||||
appendToUser(appendTo, QStringRef(&value), options, actions);
|
||||
}
|
||||
|
||||
|
||||
inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
|
||||
{
|
||||
if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) {
|
||||
|
|
@ -900,13 +893,13 @@ inline void QUrlPrivate::appendUserInfo(QString &appendTo, QUrl::FormattingOptio
|
|||
}
|
||||
}
|
||||
|
||||
if (!qt_urlRecode(appendTo, userName.constData(), userName.constEnd(), options, userNameActions))
|
||||
if (!qt_urlRecode(appendTo, userName, options, userNameActions))
|
||||
appendTo += userName;
|
||||
if (options & QUrl::RemovePassword || !hasPassword()) {
|
||||
return;
|
||||
} else {
|
||||
appendTo += QLatin1Char(':');
|
||||
if (!qt_urlRecode(appendTo, password.constData(), password.constEnd(), options, passwordActions))
|
||||
if (!qt_urlRecode(appendTo, password, options, passwordActions))
|
||||
appendTo += password;
|
||||
}
|
||||
}
|
||||
|
|
@ -1178,7 +1171,7 @@ inline void QUrlPrivate::appendHost(QString &appendTo, QUrl::FormattingOptions o
|
|||
if (host.at(0).unicode() == '[') {
|
||||
// IPv6 addresses might contain a zone-id which needs to be recoded
|
||||
if (options != 0)
|
||||
if (qt_urlRecode(appendTo, host.constBegin(), host.constEnd(), options, nullptr))
|
||||
if (qt_urlRecode(appendTo, host, options, nullptr))
|
||||
return;
|
||||
appendTo += host;
|
||||
} else {
|
||||
|
|
@ -1220,7 +1213,7 @@ static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar
|
|||
--end;
|
||||
|
||||
QString decoded;
|
||||
if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, begin, end, QUrl::FullyDecoded, nullptr)) {
|
||||
if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, QStringView{begin, end}, QUrl::FullyDecoded, nullptr)) {
|
||||
begin = decoded.constBegin();
|
||||
end = decoded.constEnd();
|
||||
}
|
||||
|
|
@ -1251,7 +1244,7 @@ static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end
|
|||
if (mode == QUrl::TolerantMode) {
|
||||
// this struct is kept in automatic storage because it's only 4 bytes
|
||||
const ushort decodeColon[] = { decode(':'), 0 };
|
||||
if (qt_urlRecode(decoded, begin, end, QUrl::ComponentFormattingOption::PrettyDecoded, decodeColon) == 0)
|
||||
if (qt_urlRecode(decoded, QStringView{begin, end}, QUrl::ComponentFormattingOption::PrettyDecoded, decodeColon) == 0)
|
||||
decoded = QString(begin, end-begin);
|
||||
} else {
|
||||
decoded = QString(begin, end-begin);
|
||||
|
|
@ -1351,7 +1344,7 @@ inline bool QUrlPrivate::setHost(const QString &value, int from, int iend, QUrl:
|
|||
|
||||
// check for percent-encoding first
|
||||
QString s;
|
||||
if (mode == QUrl::TolerantMode && qt_urlRecode(s, begin, end, { }, nullptr)) {
|
||||
if (mode == QUrl::TolerantMode && qt_urlRecode(s, QStringView{begin, end}, { }, nullptr)) {
|
||||
// something was decoded
|
||||
// anything encoded left?
|
||||
int pos = s.indexOf(QChar(0x25)); // '%'
|
||||
|
|
|
|||
|
|
@ -58,8 +58,9 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// in qurlrecode.cpp
|
||||
extern Q_AUTOTEST_EXPORT int qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end,
|
||||
QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications = nullptr);
|
||||
extern Q_AUTOTEST_EXPORT qsizetype qt_urlRecode(QString &appendTo, QStringView url,
|
||||
QUrl::ComponentFormattingOptions encoding,
|
||||
const ushort *tableModifications = nullptr);
|
||||
|
||||
// in qurlidna.cpp
|
||||
enum AceLeadingDot { AllowLeadingDot, ForbidLeadingDot };
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ inline QString QUrlQueryPrivate::recodeFromUser(const QString &input) const
|
|||
decode('#'),
|
||||
0
|
||||
};
|
||||
if (qt_urlRecode(output, input.constData(), input.constData() + input.length(),
|
||||
if (qt_urlRecode(output, input,
|
||||
QUrl::DecodeReserved,
|
||||
prettyDecodedActions))
|
||||
return output;
|
||||
|
|
@ -261,7 +261,7 @@ inline QString QUrlQueryPrivate::recodeToUser(const QString &input, QUrl::Compon
|
|||
|
||||
if (!(encoding & QUrl::EncodeDelimiters)) {
|
||||
QString output;
|
||||
if (qt_urlRecode(output, input.constData(), input.constData() + input.length(),
|
||||
if (qt_urlRecode(output, input,
|
||||
encoding, nullptr))
|
||||
return output;
|
||||
return input;
|
||||
|
|
@ -271,7 +271,7 @@ inline QString QUrlQueryPrivate::recodeToUser(const QString &input, QUrl::Compon
|
|||
ushort actions[] = { encode(pairDelimiter.unicode()), encode(valueDelimiter.unicode()),
|
||||
encode('#'), 0 };
|
||||
QString output;
|
||||
if (qt_urlRecode(output, input.constData(), input.constData() + input.length(), encoding, actions))
|
||||
if (qt_urlRecode(output, input, encoding, actions))
|
||||
return output;
|
||||
return input;
|
||||
}
|
||||
|
|
@ -306,7 +306,7 @@ void QUrlQueryPrivate::setQuery(const QString &query)
|
|||
// delimiter points to the value delimiter or to the end of this pair
|
||||
|
||||
QString key;
|
||||
if (!qt_urlRecode(key, begin, delimiter,
|
||||
if (!qt_urlRecode(key, QStringView{begin, delimiter},
|
||||
QUrl::DecodeReserved,
|
||||
prettyDecodedActions))
|
||||
key = QString(begin, delimiter - begin);
|
||||
|
|
@ -319,7 +319,7 @@ void QUrlQueryPrivate::setQuery(const QString &query)
|
|||
itemList.append(qMakePair(key, QString(0, Qt::Uninitialized)));
|
||||
} else {
|
||||
QString value;
|
||||
if (!qt_urlRecode(value, delimiter + 1, pos,
|
||||
if (!qt_urlRecode(value, QStringView{delimiter + 1, pos},
|
||||
QUrl::DecodeReserved,
|
||||
prettyDecodedActions))
|
||||
value = QString(delimiter + 1, pos - delimiter - 1);
|
||||
|
|
@ -492,7 +492,7 @@ void QUrlQuery::setQuery(const QString &queryString)
|
|||
static void recodeAndAppend(QString &to, const QString &input,
|
||||
QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications)
|
||||
{
|
||||
if (!qt_urlRecode(to, input.constData(), input.constData() + input.length(), encoding, tableModifications))
|
||||
if (!qt_urlRecode(to, input, encoding, tableModifications))
|
||||
to += input;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -671,13 +671,13 @@ static void maskTable(uchar (&table)[N], const uchar (&mask)[N])
|
|||
meaning "%25" (all percents in the same content).
|
||||
*/
|
||||
|
||||
Q_AUTOTEST_EXPORT int
|
||||
qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end,
|
||||
Q_AUTOTEST_EXPORT qsizetype
|
||||
qt_urlRecode(QString &appendTo, QStringView in,
|
||||
QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications)
|
||||
{
|
||||
uchar actionTable[sizeof defaultActionTable];
|
||||
if (encoding == QUrl::FullyDecoded) {
|
||||
return int(decode(appendTo, QStringView{begin, end}));
|
||||
return int(decode(appendTo, in));
|
||||
}
|
||||
|
||||
memcpy(actionTable, defaultActionTable, sizeof actionTable);
|
||||
|
|
@ -691,7 +691,7 @@ qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end,
|
|||
actionTable[uchar(*p) - ' '] = *p >> 8;
|
||||
}
|
||||
|
||||
return recode(appendTo, reinterpret_cast<const ushort *>(begin), reinterpret_cast<const ushort *>(end),
|
||||
return recode(appendTo, reinterpret_cast<const ushort *>(in.begin()), reinterpret_cast<const ushort *>(in.end()),
|
||||
encoding, actionTable, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -847,7 +847,7 @@ void tst_QUrlInternal::correctEncodedMistakes()
|
|||
QString dataTag = QTest::currentDataTag();
|
||||
QString output = dataTag;
|
||||
|
||||
if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), { }))
|
||||
if (!qt_urlRecode(output, input, { }))
|
||||
output += input;
|
||||
QCOMPARE(output, dataTag + expected);
|
||||
|
||||
|
|
@ -855,7 +855,7 @@ void tst_QUrlInternal::correctEncodedMistakes()
|
|||
output = dataTag;
|
||||
QString expected2 = QUrl::fromPercentEncoding(expected.toLatin1());
|
||||
|
||||
if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::FullyDecoded))
|
||||
if (!qt_urlRecode(output, input, QUrl::FullyDecoded))
|
||||
output += input;
|
||||
QCOMPARE(output, dataTag + expected2);
|
||||
}
|
||||
|
|
@ -1019,7 +1019,7 @@ void tst_QUrlInternal::encodingRecode()
|
|||
QString output = QTest::currentDataTag();
|
||||
expected.prepend(output);
|
||||
|
||||
if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), encodingMode))
|
||||
if (!qt_urlRecode(output, input, encodingMode))
|
||||
output += input;
|
||||
QCOMPARE(output, expected);
|
||||
}
|
||||
|
|
@ -1047,19 +1047,19 @@ void tst_QUrlInternal::encodingRecodeInvalidUtf8()
|
|||
// prepend some data to be sure that it remains there
|
||||
QString output = QTest::currentDataTag();
|
||||
|
||||
if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::PrettyDecoded))
|
||||
if (!qt_urlRecode(output, input, QUrl::PrettyDecoded))
|
||||
output += input;
|
||||
QCOMPARE(output, QTest::currentDataTag() + input);
|
||||
|
||||
// this is just control
|
||||
output = QTest::currentDataTag();
|
||||
if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::FullyEncoded))
|
||||
if (!qt_urlRecode(output, input, QUrl::FullyEncoded))
|
||||
output += input;
|
||||
QCOMPARE(output, QTest::currentDataTag() + input);
|
||||
|
||||
// verify for security reasons that all bad UTF-8 data got replaced by QChar::ReplacementCharacter
|
||||
output = QTest::currentDataTag();
|
||||
if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::FullyEncoded))
|
||||
if (!qt_urlRecode(output, input, QUrl::FullyEncoded))
|
||||
output += input;
|
||||
for (int i = int(strlen(QTest::currentDataTag())); i < output.length(); ++i) {
|
||||
QVERIFY2(output.at(i).unicode() < 0x80 || output.at(i) == QChar::ReplacementCharacter,
|
||||
|
|
|
|||
Loading…
Reference in New Issue