QSettingsPrivate: fold from/to parameters into the view they bound
Two methods of the private class used to take a QByteArray with from and to indices into it, for where to start and stop a scan. Now that they take a QByteArrayView, those parameters can be used by the caller to shorten the view to the desired portion. Change-Id: Id1586afb87a9e8a189b69e485278375ff504fb7b Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
parent
08d20ee850
commit
605c747321
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2022 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
@ -236,7 +236,7 @@ void QLoggingSettingsParser::parseNextLine(QStringView line)
|
||||
const auto key = line.left(equalPos).trimmed();
|
||||
#if QT_CONFIG(settings)
|
||||
QString tmp;
|
||||
QSettingsPrivate::iniUnescapedKey(key.toUtf8(), 0, key.length(), tmp);
|
||||
QSettingsPrivate::iniUnescapedKey(key.toUtf8(), tmp);
|
||||
QStringView pattern = qToStringViewIgnoringNull(tmp);
|
||||
#else
|
||||
QStringView pattern = key;
|
||||
|
@ -573,9 +573,9 @@ void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result)
|
||||
}
|
||||
}
|
||||
|
||||
bool QSettingsPrivate::iniUnescapedKey(QByteArrayView key, int from, int to, QString &result)
|
||||
bool QSettingsPrivate::iniUnescapedKey(QByteArrayView key, QString &result)
|
||||
{
|
||||
const QString decoded = QString::fromUtf8(key.first(to).sliced(from));
|
||||
const QString decoded = QString::fromUtf8(key);
|
||||
const qsizetype size = decoded.size();
|
||||
result.reserve(result.length() + size);
|
||||
qsizetype i = 0;
|
||||
@ -740,7 +740,7 @@ void QSettingsPrivate::iniEscapedStringList(const QStringList &strs, QByteArray
|
||||
}
|
||||
}
|
||||
|
||||
bool QSettingsPrivate::iniUnescapedStringList(QByteArrayView str, int from, int to,
|
||||
bool QSettingsPrivate::iniUnescapedStringList(QByteArrayView str,
|
||||
QString &stringResult, QStringList &stringListResult)
|
||||
{
|
||||
static const char escapeCodes[][2] =
|
||||
@ -762,22 +762,22 @@ bool QSettingsPrivate::iniUnescapedStringList(QByteArrayView str, int from, int
|
||||
bool inQuotedString = false;
|
||||
bool currentValueIsQuoted = false;
|
||||
char16_t escapeVal = 0;
|
||||
int i = from;
|
||||
int i = 0;
|
||||
char ch;
|
||||
QStringDecoder fromUtf8(QStringDecoder::Utf8);
|
||||
|
||||
StSkipSpaces:
|
||||
while (i < to && ((ch = str.at(i)) == ' ' || ch == '\t'))
|
||||
while (i < str.size() && ((ch = str.at(i)) == ' ' || ch == '\t'))
|
||||
++i;
|
||||
// fallthrough
|
||||
|
||||
StNormal:
|
||||
int chopLimit = stringResult.length();
|
||||
while (i < to) {
|
||||
while (i < str.size()) {
|
||||
switch (str.at(i)) {
|
||||
case '\\':
|
||||
++i;
|
||||
if (i >= to)
|
||||
if (i >= str.size())
|
||||
goto end;
|
||||
|
||||
ch = str.at(i++);
|
||||
@ -791,7 +791,7 @@ StNormal:
|
||||
if (ch == 'x') {
|
||||
escapeVal = 0;
|
||||
|
||||
if (i >= to)
|
||||
if (i >= str.size())
|
||||
goto end;
|
||||
|
||||
ch = str.at(i);
|
||||
@ -801,7 +801,7 @@ StNormal:
|
||||
escapeVal = ch - '0';
|
||||
goto StOctEscape;
|
||||
} else if (ch == '\n' || ch == '\r') {
|
||||
if (i < to) {
|
||||
if (i < str.size()) {
|
||||
char ch2 = str.at(i);
|
||||
// \n, \r, \r\n, and \n\r are legitimate line terminators in INI files
|
||||
if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch)
|
||||
@ -837,7 +837,7 @@ StNormal:
|
||||
Q_FALLTHROUGH();
|
||||
default: {
|
||||
int j = i + 1;
|
||||
while (j < to) {
|
||||
while (j < str.size()) {
|
||||
ch = str.at(j);
|
||||
if (ch == '\\' || ch == '"' || ch == ',')
|
||||
break;
|
||||
@ -854,7 +854,7 @@ StNormal:
|
||||
goto end;
|
||||
|
||||
StHexEscape:
|
||||
if (i >= to) {
|
||||
if (i >= str.size()) {
|
||||
stringResult += escapeVal;
|
||||
goto end;
|
||||
}
|
||||
@ -873,7 +873,7 @@ StHexEscape:
|
||||
}
|
||||
|
||||
StOctEscape:
|
||||
if (i >= to) {
|
||||
if (i >= str.size()) {
|
||||
stringResult += escapeVal;
|
||||
goto end;
|
||||
}
|
||||
@ -1659,7 +1659,7 @@ bool QConfFileSettingsPrivate::readIniFile(QByteArrayView data,
|
||||
currentSection = QLatin1StringView(iniSection.constData() + 1);
|
||||
} else {
|
||||
currentSection.clear();
|
||||
iniUnescapedKey(iniSection, 0, iniSection.size(), currentSection);
|
||||
iniUnescapedKey(iniSection, currentSection);
|
||||
}
|
||||
currentSection += u'/';
|
||||
}
|
||||
@ -1705,12 +1705,14 @@ bool QConfFileSettingsPrivate::readIniSection(const QSettingsKey §ion, QByte
|
||||
int valueStart = equalsPos + 1;
|
||||
|
||||
QString key = section.originalCaseKey();
|
||||
bool keyIsLowercase = (iniUnescapedKey(data, lineStart, keyEnd, key) && sectionIsLowercase);
|
||||
bool keyIsLowercase
|
||||
= iniUnescapedKey(data.first(keyEnd).sliced(lineStart), key) && sectionIsLowercase;
|
||||
|
||||
QString strValue;
|
||||
strValue.reserve(lineLen - (valueStart - lineStart));
|
||||
bool isStringList = iniUnescapedStringList(data, valueStart, lineStart + lineLen,
|
||||
strValue, strListValue);
|
||||
bool isStringList
|
||||
= iniUnescapedStringList(data.first(lineStart + lineLen).sliced(valueStart),
|
||||
strValue, strListValue);
|
||||
QVariant variant;
|
||||
if (isStringList) {
|
||||
variant = stringListToVariantList(strListValue);
|
||||
|
@ -231,11 +231,11 @@ public:
|
||||
static QString variantToString(const QVariant &v);
|
||||
static QVariant stringToVariant(const QString &s);
|
||||
static void iniEscapedKey(const QString &key, QByteArray &result);
|
||||
static bool iniUnescapedKey(QByteArrayView key, int from, int to, QString &result);
|
||||
static bool iniUnescapedKey(QByteArrayView key, QString &result);
|
||||
static void iniEscapedString(const QString &str, QByteArray &result);
|
||||
static void iniEscapedStringList(const QStringList &strs, QByteArray &result);
|
||||
static bool iniUnescapedStringList(QByteArrayView str, int from, int to,
|
||||
QString &stringResult, QStringList &stringListResult);
|
||||
static bool iniUnescapedStringList(QByteArrayView str, QString &stringResult,
|
||||
QStringList &stringListResult);
|
||||
static QStringList splitArgs(const QString &s, int idx);
|
||||
|
||||
QSettings::Format format;
|
||||
|
@ -2715,7 +2715,7 @@ static QByteArray iniEscapedKey(const QString &str)
|
||||
static QString iniUnescapedKey(const QByteArray &ba)
|
||||
{
|
||||
QString result;
|
||||
QSettingsPrivate::iniUnescapedKey(ba, 0, ba.size(), result);
|
||||
QSettingsPrivate::iniUnescapedKey(ba, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -2730,7 +2730,7 @@ static QStringList iniUnescapedStringList(const QByteArray &ba)
|
||||
{
|
||||
QStringList result;
|
||||
QString str;
|
||||
bool isStringList = QSettingsPrivate::iniUnescapedStringList(ba, 0, ba.size(), str, result);
|
||||
bool isStringList = QSettingsPrivate::iniUnescapedStringList(ba, str, result);
|
||||
if (!isStringList)
|
||||
result = QStringList(str);
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user