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/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** 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();
|
const auto key = line.left(equalPos).trimmed();
|
||||||
#if QT_CONFIG(settings)
|
#if QT_CONFIG(settings)
|
||||||
QString tmp;
|
QString tmp;
|
||||||
QSettingsPrivate::iniUnescapedKey(key.toUtf8(), 0, key.length(), tmp);
|
QSettingsPrivate::iniUnescapedKey(key.toUtf8(), tmp);
|
||||||
QStringView pattern = qToStringViewIgnoringNull(tmp);
|
QStringView pattern = qToStringViewIgnoringNull(tmp);
|
||||||
#else
|
#else
|
||||||
QStringView pattern = key;
|
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();
|
const qsizetype size = decoded.size();
|
||||||
result.reserve(result.length() + size);
|
result.reserve(result.length() + size);
|
||||||
qsizetype i = 0;
|
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)
|
QString &stringResult, QStringList &stringListResult)
|
||||||
{
|
{
|
||||||
static const char escapeCodes[][2] =
|
static const char escapeCodes[][2] =
|
||||||
@ -762,22 +762,22 @@ bool QSettingsPrivate::iniUnescapedStringList(QByteArrayView str, int from, int
|
|||||||
bool inQuotedString = false;
|
bool inQuotedString = false;
|
||||||
bool currentValueIsQuoted = false;
|
bool currentValueIsQuoted = false;
|
||||||
char16_t escapeVal = 0;
|
char16_t escapeVal = 0;
|
||||||
int i = from;
|
int i = 0;
|
||||||
char ch;
|
char ch;
|
||||||
QStringDecoder fromUtf8(QStringDecoder::Utf8);
|
QStringDecoder fromUtf8(QStringDecoder::Utf8);
|
||||||
|
|
||||||
StSkipSpaces:
|
StSkipSpaces:
|
||||||
while (i < to && ((ch = str.at(i)) == ' ' || ch == '\t'))
|
while (i < str.size() && ((ch = str.at(i)) == ' ' || ch == '\t'))
|
||||||
++i;
|
++i;
|
||||||
// fallthrough
|
// fallthrough
|
||||||
|
|
||||||
StNormal:
|
StNormal:
|
||||||
int chopLimit = stringResult.length();
|
int chopLimit = stringResult.length();
|
||||||
while (i < to) {
|
while (i < str.size()) {
|
||||||
switch (str.at(i)) {
|
switch (str.at(i)) {
|
||||||
case '\\':
|
case '\\':
|
||||||
++i;
|
++i;
|
||||||
if (i >= to)
|
if (i >= str.size())
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
ch = str.at(i++);
|
ch = str.at(i++);
|
||||||
@ -791,7 +791,7 @@ StNormal:
|
|||||||
if (ch == 'x') {
|
if (ch == 'x') {
|
||||||
escapeVal = 0;
|
escapeVal = 0;
|
||||||
|
|
||||||
if (i >= to)
|
if (i >= str.size())
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
ch = str.at(i);
|
ch = str.at(i);
|
||||||
@ -801,7 +801,7 @@ StNormal:
|
|||||||
escapeVal = ch - '0';
|
escapeVal = ch - '0';
|
||||||
goto StOctEscape;
|
goto StOctEscape;
|
||||||
} else if (ch == '\n' || ch == '\r') {
|
} else if (ch == '\n' || ch == '\r') {
|
||||||
if (i < to) {
|
if (i < str.size()) {
|
||||||
char ch2 = str.at(i);
|
char ch2 = str.at(i);
|
||||||
// \n, \r, \r\n, and \n\r are legitimate line terminators in INI files
|
// \n, \r, \r\n, and \n\r are legitimate line terminators in INI files
|
||||||
if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch)
|
if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch)
|
||||||
@ -837,7 +837,7 @@ StNormal:
|
|||||||
Q_FALLTHROUGH();
|
Q_FALLTHROUGH();
|
||||||
default: {
|
default: {
|
||||||
int j = i + 1;
|
int j = i + 1;
|
||||||
while (j < to) {
|
while (j < str.size()) {
|
||||||
ch = str.at(j);
|
ch = str.at(j);
|
||||||
if (ch == '\\' || ch == '"' || ch == ',')
|
if (ch == '\\' || ch == '"' || ch == ',')
|
||||||
break;
|
break;
|
||||||
@ -854,7 +854,7 @@ StNormal:
|
|||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
StHexEscape:
|
StHexEscape:
|
||||||
if (i >= to) {
|
if (i >= str.size()) {
|
||||||
stringResult += escapeVal;
|
stringResult += escapeVal;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -873,7 +873,7 @@ StHexEscape:
|
|||||||
}
|
}
|
||||||
|
|
||||||
StOctEscape:
|
StOctEscape:
|
||||||
if (i >= to) {
|
if (i >= str.size()) {
|
||||||
stringResult += escapeVal;
|
stringResult += escapeVal;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -1659,7 +1659,7 @@ bool QConfFileSettingsPrivate::readIniFile(QByteArrayView data,
|
|||||||
currentSection = QLatin1StringView(iniSection.constData() + 1);
|
currentSection = QLatin1StringView(iniSection.constData() + 1);
|
||||||
} else {
|
} else {
|
||||||
currentSection.clear();
|
currentSection.clear();
|
||||||
iniUnescapedKey(iniSection, 0, iniSection.size(), currentSection);
|
iniUnescapedKey(iniSection, currentSection);
|
||||||
}
|
}
|
||||||
currentSection += u'/';
|
currentSection += u'/';
|
||||||
}
|
}
|
||||||
@ -1705,12 +1705,14 @@ bool QConfFileSettingsPrivate::readIniSection(const QSettingsKey §ion, QByte
|
|||||||
int valueStart = equalsPos + 1;
|
int valueStart = equalsPos + 1;
|
||||||
|
|
||||||
QString key = section.originalCaseKey();
|
QString key = section.originalCaseKey();
|
||||||
bool keyIsLowercase = (iniUnescapedKey(data, lineStart, keyEnd, key) && sectionIsLowercase);
|
bool keyIsLowercase
|
||||||
|
= iniUnescapedKey(data.first(keyEnd).sliced(lineStart), key) && sectionIsLowercase;
|
||||||
|
|
||||||
QString strValue;
|
QString strValue;
|
||||||
strValue.reserve(lineLen - (valueStart - lineStart));
|
strValue.reserve(lineLen - (valueStart - lineStart));
|
||||||
bool isStringList = iniUnescapedStringList(data, valueStart, lineStart + lineLen,
|
bool isStringList
|
||||||
strValue, strListValue);
|
= iniUnescapedStringList(data.first(lineStart + lineLen).sliced(valueStart),
|
||||||
|
strValue, strListValue);
|
||||||
QVariant variant;
|
QVariant variant;
|
||||||
if (isStringList) {
|
if (isStringList) {
|
||||||
variant = stringListToVariantList(strListValue);
|
variant = stringListToVariantList(strListValue);
|
||||||
|
@ -231,11 +231,11 @@ public:
|
|||||||
static QString variantToString(const QVariant &v);
|
static QString variantToString(const QVariant &v);
|
||||||
static QVariant stringToVariant(const QString &s);
|
static QVariant stringToVariant(const QString &s);
|
||||||
static void iniEscapedKey(const QString &key, QByteArray &result);
|
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 iniEscapedString(const QString &str, QByteArray &result);
|
||||||
static void iniEscapedStringList(const QStringList &strs, QByteArray &result);
|
static void iniEscapedStringList(const QStringList &strs, QByteArray &result);
|
||||||
static bool iniUnescapedStringList(QByteArrayView str, int from, int to,
|
static bool iniUnescapedStringList(QByteArrayView str, QString &stringResult,
|
||||||
QString &stringResult, QStringList &stringListResult);
|
QStringList &stringListResult);
|
||||||
static QStringList splitArgs(const QString &s, int idx);
|
static QStringList splitArgs(const QString &s, int idx);
|
||||||
|
|
||||||
QSettings::Format format;
|
QSettings::Format format;
|
||||||
|
@ -2715,7 +2715,7 @@ static QByteArray iniEscapedKey(const QString &str)
|
|||||||
static QString iniUnescapedKey(const QByteArray &ba)
|
static QString iniUnescapedKey(const QByteArray &ba)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
QSettingsPrivate::iniUnescapedKey(ba, 0, ba.size(), result);
|
QSettingsPrivate::iniUnescapedKey(ba, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2730,7 +2730,7 @@ static QStringList iniUnescapedStringList(const QByteArray &ba)
|
|||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
QString str;
|
QString str;
|
||||||
bool isStringList = QSettingsPrivate::iniUnescapedStringList(ba, 0, ba.size(), str, result);
|
bool isStringList = QSettingsPrivate::iniUnescapedStringList(ba, str, result);
|
||||||
if (!isStringList)
|
if (!isStringList)
|
||||||
result = QStringList(str);
|
result = QStringList(str);
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user