aboutsummaryrefslogtreecommitdiff
path: root/src/core/kconfigini.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2021-02-22 17:38:09 +0200
committerAhmad Samir <a.samirh78@gmail.com>2021-02-22 17:38:09 +0200
commit8bed00ab34e31f2b9c70026d418d923913325798 (patch)
treef289c15575415a36bc19c047a2037998e9b11ce8 /src/core/kconfigini.cpp
parent186755fd56b58dc97250846c5305ef89f9487f86 (diff)
downloadkconfig-8bed00ab34e31f2b9c70026d418d923913325798.tar.gz
kconfig-8bed00ab34e31f2b9c70026d418d923913325798.tar.bz2
Run clang-format on all cpp/h files
NO_CHANGELOG
Diffstat (limited to 'src/core/kconfigini.cpp')
-rw-r--r--src/core/kconfigini.cpp258
1 files changed, 127 insertions, 131 deletions
diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp
index 96cd3763..6271bcd5 100644
--- a/src/core/kconfigini.cpp
+++ b/src/core/kconfigini.cpp
@@ -9,26 +9,26 @@
#include "kconfigini_p.h"
+#include "bufferfragment_p.h"
#include "kconfig.h"
+#include "kconfig_core_log_settings.h"
#include "kconfigbackend_p.h"
-#include "bufferfragment_p.h"
#include "kconfigdata.h"
-#include "kconfig_core_log_settings.h"
-#include <QSaveFile>
-#include <QLockFile>
#include <QDateTime>
+#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
-#include <QDebug>
+#include <QLockFile>
+#include <QSaveFile>
#include <qplatformdefs.h>
#ifndef Q_OS_WIN
#include <unistd.h> // getuid, close
#endif
-#include <sys/types.h> // uid_t
#include <fcntl.h> // open
+#include <sys/types.h> // uid_t
KCONFIGCORE_EXPORT bool kde_kiosk_exception = false; // flag to disable kiosk restrictions
@@ -44,12 +44,12 @@ static QByteArray lookup(const KConfigIniBackend::BufferFragment fragment, QHash
QString KConfigIniBackend::warningProlog(const QFile &file, int line)
{
- return QStringLiteral("KConfigIni: In file %2, line %1: ")
- .arg(line).arg(file.fileName());
+ return QStringLiteral("KConfigIni: In file %2, line %1: ").arg(line).arg(file.fileName());
}
KConfigIniBackend::KConfigIniBackend()
- : KConfigBackend(), lockFile(nullptr)
+ : KConfigBackend()
+ , lockFile(nullptr)
{
}
@@ -57,18 +57,14 @@ KConfigIniBackend::~KConfigIniBackend()
{
}
-KConfigBackend::ParseInfo
-KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entryMap,
- ParseOptions options)
+KConfigBackend::ParseInfo KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entryMap, ParseOptions options)
{
return parseConfig(currentLocale, entryMap, options, false);
}
// merging==true is the merging that happens at the beginning of writeConfig:
// merge changes in the on-disk file with the changes in the KConfig object.
-KConfigBackend::ParseInfo
-KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entryMap,
- ParseOptions options, bool merging)
+KConfigBackend::ParseInfo KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entryMap, ParseOptions options, bool merging)
{
if (filePath().isEmpty() || !QFile::exists(filePath())) {
return ParseOk;
@@ -137,8 +133,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
}
++end;
}
- if (end + 1 == line.length() && start + 2 == end &&
- line.at(start) == '$' && line.at(start + 1) == 'i') {
+ if (end + 1 == line.length() && start + 2 == end && line.at(start) == '$' && line.at(start + 1) == 'i') {
if (newGroup.isEmpty()) {
fileOptionImmutable = !kde_kiosk_exception;
} else {
@@ -162,14 +157,14 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
}
if (groupOptionImmutable)
- // Do not make the groups immutable until the entries from
- // this file have been added.
+ // Do not make the groups immutable until the entries from
+ // this file have been added.
{
immutableGroups.append(currentGroup);
}
} else {
if (groupSkip && !bDefault) {
- continue; // skip entry
+ continue; // skip entry
}
BufferFragment aKey;
@@ -199,8 +194,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
while ((start = aKey.lastIndexOf('[')) >= 0) {
int end = aKey.indexOf(']', start);
if (end < 0) {
- qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo)
- << "Invalid entry (missing ']')";
+ qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (missing ']')";
goto next_line;
} else if (end > start + 1 && aKey.at(start + 1) == '$') { // found option(s)
int i = start + 2;
@@ -229,8 +223,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
}
} else { // found a locale
if (!locale.isNull()) {
- qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo)
- << "Invalid entry (second locale!?)";
+ qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (second locale!?)";
goto next_line;
}
@@ -250,7 +243,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
if (merging) {
entryOptions |= KEntryMap::EntryRawKey;
} else {
- goto next_line; // skip this entry if we're not merging
+ goto next_line; // skip this entry if we're not merging
}
}
}
@@ -295,8 +288,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
return fileOptionImmutable ? ParseImmutable : ParseOk;
}
-void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file,
- const KEntryMap &map, bool defaultGroup, bool &firstEntry)
+void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file, const KEntryMap &map, bool defaultGroup, bool &firstEntry)
{
QByteArray currentGroup;
bool groupIsImmutable = false;
@@ -306,7 +298,7 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file,
// Either process the default group or all others
if ((key.mGroup != "<default>") == defaultGroup) {
- continue; // skip
+ continue; // skip
}
// the only thing we care about groups is, is it immutable?
@@ -366,9 +358,9 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file,
}
if (currentEntry.bDeleted) {
if (currentEntry.bImmutable) {
- file.write("[$di]", 5); // Deleted + immutable
+ file.write("[$di]", 5); // Deleted + immutable
} else {
- file.write("[$d]", 4); // Deleted
+ file.write("[$d]", 4); // Deleted
}
} else {
if (currentEntry.bImmutable || currentEntry.bExpand) {
@@ -399,8 +391,7 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file,
writeEntries(locale, file, map, false, firstEntry);
}
-bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMap,
- WriteOptions options)
+bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMap, WriteOptions options)
{
Q_ASSERT(!filePath().isEmpty());
@@ -442,10 +433,10 @@ bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMa
defaultKey.bDefault = true;
if (!entryMap.contains(defaultKey)) {
writeMap.remove(key); // remove the deleted entry if there is no default
- //qDebug() << "Detected as deleted=>removed:" << key.mGroup << key.mKey << "global=" << bGlobal;
+ // qDebug() << "Detected as deleted=>removed:" << key.mGroup << key.mKey << "global=" << bGlobal;
} else {
writeMap[key] = *it; // otherwise write an explicitly deleted entry
- //qDebug() << "Detected as deleted=>[$d]:" << key.mGroup << key.mKey << "global=" << bGlobal;
+ // qDebug() << "Detected as deleted=>[$d]:" << key.mGroup << key.mKey << "global=" << bGlobal;
}
}
it->bDirty = false;
@@ -462,7 +453,7 @@ bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMa
QFileInfo fi(filePath());
if (fi.exists()) {
#ifdef Q_OS_WIN
- //TODO: getuid does not exist on windows, use GetSecurityInfo and GetTokenInformation instead
+ // TODO: getuid does not exist on windows, use GetSecurityInfo and GetTokenInformation instead
createNew = false;
#else
if (fi.ownerId() == ::getuid()) {
@@ -574,7 +565,7 @@ void KConfigIniBackend::createEnclosing()
{
const QString file = filePath();
if (file.isEmpty()) {
- return; // nothing to do
+ return; // nothing to do
}
// Create the containing dir, maybe it wasn't there
@@ -639,106 +630,112 @@ bool KConfigIniBackend::isLocked() const
return lockFile && lockFile->isLocked();
}
-namespace {
- // serialize an escaped byte at the end of @param data
- // @param data should have room for 4 bytes
- char* escapeByte(char* data, unsigned char s) {
- static const char nibbleLookup[] = {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
- };
- *data++ = '\\';
- *data++ = 'x';
- *data++ = nibbleLookup[s >> 4];
- *data++ = nibbleLookup[s & 0x0f];
- return data;
- }
+namespace
+{
+// serialize an escaped byte at the end of @param data
+// @param data should have room for 4 bytes
+char *escapeByte(char *data, unsigned char s)
+{
+ static const char nibbleLookup[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+ *data++ = '\\';
+ *data++ = 'x';
+ *data++ = nibbleLookup[s >> 4];
+ *data++ = nibbleLookup[s & 0x0f];
+ return data;
+}
- // Struct that represents a multi-byte UTF-8 character.
- // This struct is used to keep track of bytes that seem to be valid
- // UTF-8.
- struct Utf8Char {
- public:
- unsigned char bytes[4];
- unsigned char count;
- unsigned char charLength;
-
- Utf8Char() {
- clear();
- charLength = 0;
- }
- void clear() {
- count = 0;
- }
- // Add a byte to the UTF8 character.
- // When an additional byte leads to an invalid character, return false.
- bool addByte(unsigned char b) {
- if (count == 0) {
- if (b > 0xc1 && (b & 0xe0) == 0xc0) {
- charLength = 2;
- } else if ((b & 0xf0) == 0xe0) {
- charLength = 3;
- } else if (b < 0xf5 && (b & 0xf8) == 0xf0) {
- charLength = 4;
- } else {
- return false;
+// Struct that represents a multi-byte UTF-8 character.
+// This struct is used to keep track of bytes that seem to be valid
+// UTF-8.
+struct Utf8Char {
+public:
+ unsigned char bytes[4];
+ unsigned char count;
+ unsigned char charLength;
+
+ Utf8Char()
+ {
+ clear();
+ charLength = 0;
+ }
+ void clear()
+ {
+ count = 0;
+ }
+ // Add a byte to the UTF8 character.
+ // When an additional byte leads to an invalid character, return false.
+ bool addByte(unsigned char b)
+ {
+ if (count == 0) {
+ if (b > 0xc1 && (b & 0xe0) == 0xc0) {
+ charLength = 2;
+ } else if ((b & 0xf0) == 0xe0) {
+ charLength = 3;
+ } else if (b < 0xf5 && (b & 0xf8) == 0xf0) {
+ charLength = 4;
+ } else {
+ return false;
+ }
+ bytes[0] = b;
+ count = 1;
+ } else if (count < 4 && (b & 0xc0) == 0x80) {
+ if (count == 1) {
+ if (charLength == 3 && bytes[0] == 0xe0 && b < 0xa0) {
+ return false; // overlong 3 byte sequence
}
- bytes[0] = b;
- count = 1;
- } else if (count < 4 && (b & 0xc0) == 0x80) {
- if (count == 1) {
- if (charLength == 3 && bytes[0] == 0xe0 && b < 0xa0) {
- return false; // overlong 3 byte sequence
+ if (charLength == 4) {
+ if (bytes[0] == 0xf0 && b < 0x90) {
+ return false; // overlong 4 byte sequence
}
- if (charLength == 4) {
- if (bytes[0] == 0xf0 && b < 0x90) {
- return false; // overlong 4 byte sequence
- }
- if (bytes[0] == 0xf4 && b > 0x8f) {
- return false; // Unicode value larger than U+10FFFF
- }
+ if (bytes[0] == 0xf4 && b > 0x8f) {
+ return false; // Unicode value larger than U+10FFFF
}
}
- bytes[count++] = b;
- } else {
- return false;
}
- return true;
- }
- // Return true if Utf8Char contains one valid character.
- bool isComplete() {
- return count > 0 && count == charLength;
+ bytes[count++] = b;
+ } else {
+ return false;
}
- // Add the bytes in this UTF8 character in escaped form to data.
- char* escapeBytes(char* data) {
- for (unsigned char i = 0; i < count; ++i) {
- data = escapeByte(data, bytes[i]);
- }
- clear();
- return data;
+ return true;
+ }
+ // Return true if Utf8Char contains one valid character.
+ bool isComplete()
+ {
+ return count > 0 && count == charLength;
+ }
+ // Add the bytes in this UTF8 character in escaped form to data.
+ char *escapeBytes(char *data)
+ {
+ for (unsigned char i = 0; i < count; ++i) {
+ data = escapeByte(data, bytes[i]);
}
- // Add the bytes of the UTF8 character to a buffer.
- // Only call this if isComplete() returns true.
- char* writeUtf8(char* data) {
- for (unsigned char i = 0; i < count; ++i) {
- *data++ = bytes[i];
- }
- clear();
- return data;
+ clear();
+ return data;
+ }
+ // Add the bytes of the UTF8 character to a buffer.
+ // Only call this if isComplete() returns true.
+ char *writeUtf8(char *data)
+ {
+ for (unsigned char i = 0; i < count; ++i) {
+ *data++ = bytes[i];
}
- // Write the bytes in the UTF8 character literally, or, if the
- // character is not complete, write the escaped bytes.
- // This is useful to handle the state that remains after handling
- // all bytes in a buffer.
- char* write(char* data) {
- if (isComplete()) {
- data = writeUtf8(data);
- } else {
- data = escapeBytes(data);
- }
- return data;
+ clear();
+ return data;
+ }
+ // Write the bytes in the UTF8 character literally, or, if the
+ // character is not complete, write the escaped bytes.
+ // This is useful to handle the state that remains after handling
+ // all bytes in a buffer.
+ char *write(char *data)
+ {
+ if (isComplete()) {
+ data = writeUtf8(data);
+ } else {
+ data = escapeBytes(data);
}
- };
+ return data;
+ }
+};
}
QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, StringType type)
@@ -763,7 +760,7 @@ QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, Strin
}
Utf8Char utf8;
- for (; i < l; ++i/*, r++*/) {
+ for (; i < l; ++i /*, r++*/) {
switch (s[i]) {
default:
if (utf8.addByte(s[i])) {
@@ -847,8 +844,8 @@ char KConfigIniBackend::charFromHex(const char *str, const QFile &file, int line
} else {
QByteArray e(str, 2);
e.prepend("\\x");
- qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << "Invalid hex character " << c
- << " in \\x<nn>-type escape sequence \"" << e.constData() << "\".";
+ qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << "Invalid hex character " << c << " in \\x<nn>-type escape sequence \"" << e.constData()
+ << "\".";
return 'x';
}
}
@@ -915,8 +912,7 @@ void KConfigIniBackend::printableToString(BufferFragment *aString, const QFile &
break;
default:
*r = '\\';
- qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line)
- << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]);
+ qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]);
}
}
}