Use QStringRef() more, exploiting its new ::chop()
Change-Id: Id2201639be604b9a32b2dc5d21e675a961bee477 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ff00b2efbd
commit
8617ce5c88
@ -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.
|
// 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.
|
// the internal value is stored in its PrettyDecoded form, so that case is easy.
|
||||||
static inline void appendToUser(QString &appendTo, const QString &value, QUrl::FormattingOptions options,
|
static inline void appendToUser(QString &appendTo, const QStringRef &value, QUrl::FormattingOptions options,
|
||||||
const ushort *actions)
|
const ushort *actions)
|
||||||
{
|
{
|
||||||
if (options == QUrl::PrettyDecoded) {
|
if (options == QUrl::PrettyDecoded) {
|
||||||
@ -841,10 +841,17 @@ static inline void appendToUser(QString &appendTo, const QString &value, QUrl::F
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!qt_urlRecode(appendTo, value.constData(), value.constEnd(), options, actions))
|
if (!qt_urlRecode(appendTo, value.data(), value.end(), options, actions))
|
||||||
appendTo += value;
|
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
|
inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
|
||||||
{
|
{
|
||||||
if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) {
|
if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) {
|
||||||
@ -924,21 +931,22 @@ inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions o
|
|||||||
if (options & QUrl::NormalizePathSegments) {
|
if (options & QUrl::NormalizePathSegments) {
|
||||||
thePath = qt_normalizePathSegments(path, false);
|
thePath = qt_normalizePathSegments(path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringRef thePathRef(&thePath);
|
||||||
if (options & QUrl::RemoveFilename) {
|
if (options & QUrl::RemoveFilename) {
|
||||||
const int slash = path.lastIndexOf(QLatin1Char('/'));
|
const int slash = path.lastIndexOf(QLatin1Char('/'));
|
||||||
if (slash == -1)
|
if (slash == -1)
|
||||||
return;
|
return;
|
||||||
thePath = path.left(slash+1);
|
thePathRef = path.leftRef(slash + 1);
|
||||||
}
|
}
|
||||||
// check if we need to remove trailing slashes
|
// check if we need to remove trailing slashes
|
||||||
if (options & QUrl::StripTrailingSlash) {
|
if (options & QUrl::StripTrailingSlash) {
|
||||||
while (thePath.length() > 1 && thePath.endsWith(QLatin1Char('/')))
|
while (thePathRef.length() > 1 && thePathRef.endsWith(QLatin1Char('/')))
|
||||||
thePath.chop(1);
|
thePathRef.chop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
appendToUser(appendTo, thePath, options,
|
appendToUser(appendTo, thePathRef, options,
|
||||||
appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? pathInUrl : pathInIsolation);
|
appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? pathInUrl : pathInIsolation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QUrlPrivate::appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
|
inline void QUrlPrivate::appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
|
||||||
|
@ -400,7 +400,7 @@ static QPageSize::PageSizeId qt_idForPpdKey(const QString &ppdKey, QSize *match
|
|||||||
{
|
{
|
||||||
if (ppdKey.isEmpty())
|
if (ppdKey.isEmpty())
|
||||||
return QPageSize::Custom;
|
return QPageSize::Custom;
|
||||||
QString key = ppdKey;
|
QStringRef key(&ppdKey);
|
||||||
// Remove any Rotated or Tranverse modifiers
|
// Remove any Rotated or Tranverse modifiers
|
||||||
if (key.endsWith(QLatin1String("Rotated")))
|
if (key.endsWith(QLatin1String("Rotated")))
|
||||||
key.chop(7);
|
key.chop(7);
|
||||||
|
@ -403,8 +403,8 @@ ValueExtractor::ValueExtractor(const QVector<Declaration> &decls, const QPalette
|
|||||||
|
|
||||||
LengthData ValueExtractor::lengthValue(const Value& v)
|
LengthData ValueExtractor::lengthValue(const Value& v)
|
||||||
{
|
{
|
||||||
QString s = v.variant.toString();
|
const QString str = v.variant.toString();
|
||||||
s.reserve(s.length());
|
QStringRef s(&str);
|
||||||
LengthData data;
|
LengthData data;
|
||||||
data.unit = LengthData::None;
|
data.unit = LengthData::None;
|
||||||
if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive))
|
if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive))
|
||||||
@ -1442,11 +1442,13 @@ bool Declaration::realValue(qreal *real, const char *unit) const
|
|||||||
const Value &v = d->values.at(0);
|
const Value &v = d->values.at(0);
|
||||||
if (unit && v.type != Value::Length)
|
if (unit && v.type != Value::Length)
|
||||||
return false;
|
return false;
|
||||||
QString s = v.variant.toString();
|
const QString str = v.variant.toString();
|
||||||
|
QStringRef s(&str);
|
||||||
if (unit) {
|
if (unit) {
|
||||||
if (!s.endsWith(QLatin1String(unit), Qt::CaseInsensitive))
|
const QLatin1String unitStr(unit);
|
||||||
|
if (!s.endsWith(unitStr, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
s.chop(qstrlen(unit));
|
s.chop(unitStr.size());
|
||||||
}
|
}
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
qreal val = s.toDouble(&ok);
|
qreal val = s.toDouble(&ok);
|
||||||
@ -1459,11 +1461,13 @@ static bool intValueHelper(const QCss::Value &v, int *i, const char *unit)
|
|||||||
{
|
{
|
||||||
if (unit && v.type != Value::Length)
|
if (unit && v.type != Value::Length)
|
||||||
return false;
|
return false;
|
||||||
QString s = v.variant.toString();
|
const QString str = v.variant.toString();
|
||||||
|
QStringRef s(&str);
|
||||||
if (unit) {
|
if (unit) {
|
||||||
if (!s.endsWith(QLatin1String(unit), Qt::CaseInsensitive))
|
const QLatin1String unitStr(unit);
|
||||||
|
if (!s.endsWith(unitStr, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
s.chop(qstrlen(unit));
|
s.chop(unitStr.size());
|
||||||
}
|
}
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
int val = s.toInt(&ok);
|
int val = s.toInt(&ok);
|
||||||
|
@ -498,11 +498,13 @@ QZipReader::FileInfo QZipPrivate::fillFileInfo(int index) const
|
|||||||
|
|
||||||
// fix the file path, if broken (convert separators, eat leading and trailing ones)
|
// fix the file path, if broken (convert separators, eat leading and trailing ones)
|
||||||
fileInfo.filePath = QDir::fromNativeSeparators(fileInfo.filePath);
|
fileInfo.filePath = QDir::fromNativeSeparators(fileInfo.filePath);
|
||||||
while (!fileInfo.filePath.isEmpty() && (fileInfo.filePath.at(0) == QLatin1Char('.') || fileInfo.filePath.at(0) == QLatin1Char('/')))
|
QStringRef filePathRef(&fileInfo.filePath);
|
||||||
fileInfo.filePath = fileInfo.filePath.mid(1);
|
while (filePathRef.startsWith(QLatin1Char('.')) || filePathRef.startsWith(QLatin1Char('/')))
|
||||||
while (!fileInfo.filePath.isEmpty() && fileInfo.filePath.at(fileInfo.filePath.size() - 1) == QLatin1Char('/'))
|
filePathRef = filePathRef.mid(1);
|
||||||
fileInfo.filePath.chop(1);
|
while (filePathRef.endsWith(QLatin1Char('/')))
|
||||||
|
filePathRef.chop(1);
|
||||||
|
|
||||||
|
fileInfo.filePath = filePathRef.toString();
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user