aboutsummaryrefslogtreecommitdiff
path: root/src/core/bufferfragment_p.h
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2013-12-18 09:53:59 +0100
committerDavid Faure <faure@kde.org>2013-12-18 09:53:59 +0100
commit159963832457e6307282308455330acc7b5bd153 (patch)
treece1cc0234d37e9afc75bc86d734beb963ed57d02 /src/core/bufferfragment_p.h
parent867e7a50e6396338ab4fe9aa22ad141e4cd344d2 (diff)
downloadkconfig-159963832457e6307282308455330acc7b5bd153.tar.gz
kconfig-159963832457e6307282308455330acc7b5bd153.tar.bz2
Code reformatted using kde-dev-scripts/astyle-kdelibs.
Use git blame -w 867e7a5 to show authorship as it was before this commit.
Diffstat (limited to 'src/core/bufferfragment_p.h')
-rw-r--r--src/core/bufferfragment_p.h110
1 files changed, 60 insertions, 50 deletions
diff --git a/src/core/bufferfragment_p.h b/src/core/bufferfragment_p.h
index 5a753ad4..117d8db3 100644
--- a/src/core/bufferfragment_p.h
+++ b/src/core/bufferfragment_p.h
@@ -23,158 +23,168 @@
#define bf_isspace(str) ((str == ' ') || (str == '\t') || (str == '\r'))
-// This class provides wrapper around fragment of existing buffer (array of bytes).
+// This class provides wrapper around fragment of existing buffer (array of bytes).
// If underlying buffer gets deleted, all BufferFragment objects referencing it become invalid.
// Use toByteArray() to make deep copy of the buffer fragment.
-//
+//
// API is designed to subset of QByteArray methods with some changes:
// - trim() is like QByteArray.trimmed(), but it modifies current object
// - truncateLeft() provides way to cut off beginning of the buffer
// - split() works more like strtok_r than QByteArray.split()
// - truncateLeft() and mid() require position argument to be valid
-
-class KConfigIniBackend::BufferFragment
+
+class KConfigIniBackend::BufferFragment
{
-
+
public:
- BufferFragment() : d(0), len(0)
+ BufferFragment() : d(0), len(0)
{
}
-
- BufferFragment(char* buf, int size) : d(buf), len(size)
+
+ BufferFragment(char *buf, int size) : d(buf), len(size)
{
}
- int length() const
+ int length() const
{
return len;
}
- char at(unsigned int i) const
+ char at(unsigned int i) const
{
Q_ASSERT(i < len);
return d[i];
}
- void clear()
+ void clear()
{
len = 0;
}
- const char* constData() const
+ const char *constData() const
{
return d;
}
- char* data() const
+ char *data() const
{
return d;
}
- void trim()
+ void trim()
{
while (bf_isspace(*d) && len > 0) {
d++;
len--;
}
- while (len > 0 && bf_isspace(d[len - 1]))
+ while (len > 0 && bf_isspace(d[len - 1])) {
len--;
+ }
}
// similar to strtok_r . On first call variable pointed by start should be set to 0.
- // Each call will update *start to new starting position.
- BufferFragment split(char c, unsigned int* start)
+ // Each call will update *start to new starting position.
+ BufferFragment split(char c, unsigned int *start)
{
while (*start < len) {
int end = indexOf(c, *start);
- if (end == -1) end = len;
+ if (end == -1) {
+ end = len;
+ }
BufferFragment line(d + (*start), end - (*start));
*start = end + 1;
return line;
}
return BufferFragment();
}
-
- bool isEmpty() const
+
+ bool isEmpty() const
{
return (len == 0);
}
- BufferFragment left(unsigned int size) const
+ BufferFragment left(unsigned int size) const
{
- return BufferFragment(d, qMin(size,len));
+ return BufferFragment(d, qMin(size, len));
}
- void truncateLeft(unsigned int size)
+ void truncateLeft(unsigned int size)
{
Q_ASSERT(size <= len);
d += size;
len -= size;
}
- void truncate(unsigned int pos)
+ void truncate(unsigned int pos)
{
- if (pos < len) len = pos;
+ if (pos < len) {
+ len = pos;
+ }
}
- bool isNull() const
+ bool isNull() const
{
return (d == 0);
}
-
- BufferFragment mid(unsigned int pos, int length=-1) const
+
+ BufferFragment mid(unsigned int pos, int length = -1) const
{
Q_ASSERT(pos < len);
int size = length;
- if (length == -1 || (pos + length) > len)
+ if (length == -1 || (pos + length) > len) {
size = len - pos;
+ }
return BufferFragment(d + pos, size);
}
- bool operator==(const QByteArray& other) const
+ bool operator==(const QByteArray &other) const
{
- return (other.size() == (int)len && memcmp(d,other.constData(),len) == 0);
+ return (other.size() == (int)len && memcmp(d, other.constData(), len) == 0);
}
- bool operator!=(const QByteArray& other) const
+ bool operator!=(const QByteArray &other) const
{
- return (other.size() != (int)len || memcmp(d,other.constData(),len) != 0);
+ return (other.size() != (int)len || memcmp(d, other.constData(), len) != 0);
}
-
- int indexOf(char c, unsigned int from = 0) const
+
+ int indexOf(char c, unsigned int from = 0) const
{
- const char* cursor = d + from - 1;
- const char* end = d + len;
- while ( ++cursor < end)
- if (*cursor ==c )
- return cursor - d;
+ const char *cursor = d + from - 1;
+ const char *end = d + len;
+ while (++cursor < end)
+ if (*cursor == c) {
+ return cursor - d;
+ }
return -1;
}
- int lastIndexOf(char c) const
+ int lastIndexOf(char c) const
{
int from = len - 1;
- while (from >= 0)
- if (d[from] == c)
- return from;
- else
+ while (from >= 0)
+ if (d[from] == c) {
+ return from;
+ } else {
from--;
+ }
return -1;
}
- QByteArray toByteArray() const {
- return QByteArray(d,len);
+ QByteArray toByteArray() const
+ {
+ return QByteArray(d, len);
}
-
+
// this is faster than toByteArray, but returned QByteArray becomes invalid
// when buffer for this BufferFragment disappears
- QByteArray toVolatileByteArray() const {
+ QByteArray toVolatileByteArray() const
+ {
return QByteArray::fromRawData(d, len);
}
private:
- char* d;
+ char *d;
unsigned int len;
};