Qt 4.8
|
A compression facility for whitespace nodes. More...
#include <qcompressedwhitespace_p.h>
Static Public Functions | |
static QString | compress (const QStringRef &input) |
Compresses input into a compressed format, returned as a QString. More... | |
static QString | decompress (const QString &input) |
Decompresses input into a usual QString. More... | |
Private Types | |
enum | CharIdentifier { Space = 0x0, CR = 0x80, LF = 0x40, Tab = 0xC0 } |
enum | Constants { MaxCharCount = (1 << 6) - 1, Lower8Bits = (1 << 8) - 1, Lower6Bits = (1 << 6) - 1, UpperTwoBits = 3 << 6 } |
Private Functions | |
CompressedWhitespace () | |
This class can only be used via its static members. More... | |
Static Private Functions | |
static bool | isEven (const int number) |
Returns true if number is an even number, otherwise false . More... | |
static QChar | toChar (const CharIdentifier id) |
static quint8 | toCompressedChar (const QChar ch, const int len) |
static CharIdentifier | toIdentifier (const QChar ch) |
A compression facility for whitespace nodes.
CompressedWhitespace compresses and decompresses strings that consists of whitespace only, and do so with a scheme that is designed to do this specialized task in an efficient way. The approach is simple: each sequence of equal whitespace in the input gets coded into one byte, where the first two bits signals the type, CharIdentifier, and the remininding six bits is the count.
For instance, this scheme manages to compress a sequence of spaces followed by a new line into 16 bits(one QChar), and QString stores strings of one QChar quite efficiently, by avoiding a heap allocation.
There is no way to tell whether a QString is compressed or not.
The compression scheme originates from Saxon, by Michael Kay.
Definition at line 87 of file qcompressedwhitespace_p.h.
|
private |
We use the two upper bits for communicating what space it is.
Enumerator | |
---|---|
Space | |
CR | 0xA, \r Binary: 10000000 |
LF | 0xD, \n Binary: 01000000 |
Tab | Binary: 11000000 |
Definition at line 117 of file qcompressedwhitespace_p.h.
|
private |
Enumerator | |
---|---|
MaxCharCount | |
Lower8Bits | Binary: 11111111 |
Lower6Bits | Binary: 111111 |
UpperTwoBits |
Definition at line 141 of file qcompressedwhitespace_p.h.
|
inlineprivate |
This class can only be used via its static members.
|
static |
Compresses input
into a compressed format, returned as a QString.
The caller guarantees that input is not empty and consists only of whitespace.
The returned format is opaque. There is no way to find out whether a QString contains compressed data or not.
Definition at line 101 of file qcompressedwhitespace.cpp.
Decompresses input
into a usual QString.
input
must be a QString as per returned from compress().
Definition at line 160 of file qcompressedwhitespace.cpp.
Referenced by QPatternist::AccelTree::printStats(), and QPatternist::AccelTree::stringValue().
|
inlinestaticprivate |
Returns true
if number
is an even number, otherwise false
.
Definition at line 71 of file qcompressedwhitespace.cpp.
Referenced by compress(), and decompress().
|
inlinestaticprivate |
Definition at line 77 of file qcompressedwhitespace.cpp.
Referenced by compress().
|
inlinestaticprivate |
Definition at line 50 of file qcompressedwhitespace.cpp.
Referenced by toCompressedChar().