diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-03-22 15:02:20 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-04-01 23:03:58 +0200 |
commit | ad7a738e6d9e878c5451939dbb2ba77f92e117b9 (patch) | |
tree | 2dcfc23adf97267a3a46b91421bb3b8c828a51c7 /src/corelib/io/qsettings.cpp | |
parent | d9531593a248e19f7da7862b2870a6af2f413e75 (diff) |
Simplify parsing of a line to remove [...] enclosure
Use a view of the line, within the larger data buffer, to avoid some
complications.
Change-Id: Iaf79068487ac6b92fe9e415fb63f6b0e9ad0c5a2
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/io/qsettings.cpp')
-rw-r--r-- | src/corelib/io/qsettings.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 8c7939ccc4..44faf0619c 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -1634,21 +1634,19 @@ bool QConfFileSettingsPrivate::readIniFile(QByteArrayView data, dataPos = 3; while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) { - char ch = data.at(lineStart); - if (ch == '[') { + QByteArrayView line = data.sliced(lineStart, lineLen); + if (line.startsWith('[')) { FLUSH_CURRENT_SECTION(); - // this is a section - QByteArrayView iniSection; - qsizetype idx = data.indexOf(']', lineStart); - if (idx == -1 || idx >= lineStart + lineLen) { + // This starts a new section. + qsizetype idx = line.indexOf(']'); + Q_ASSERT(idx == -1 || idx > 0); // line[0] is '[', not ']'. + Q_ASSERT(idx < lineLen); // (including -1 < lineLen, if no ']' present.) + if (idx < 0) { ok = false; - iniSection = data.sliced(lineStart + 1, lineLen - 1); - } else { - iniSection = data.sliced(lineStart + 1, idx - lineStart - 1); + idx = lineLen; // so line.first(idx) is just line } - - iniSection = iniSection.trimmed(); + QByteArrayView iniSection = line.first(idx).sliced(1).trimmed(); if (iniSection.compare("general", Qt::CaseInsensitive) == 0) { currentSection.clear(); |