Qx v0.5.8
Qt Extensions Library
|
The Base85Encoding class provides the parameters of a particular Base85 string encoding. More...
#include <qx/core/qx-base85.h>
Public Types | |
enum | StandardEncoding { Btoa , Btoa_4_2 , Adobe , Z85 , Rfc_1924 } |
Public Member Functions | |
Base85Encoding () | |
Base85Encoding (StandardEncoding enc) | |
char | characterAt (int i) const |
int | characterPosition (char ch) const |
const std::array< char, 85 > & | characterSet () const |
bool | containsCharacter (char ch, bool shortcut=true) const |
bool | isHandlePadding () const |
bool | isValid () const |
bool | operator!= (const Base85Encoding &other) const |
bool | operator== (const Base85Encoding &other) const |
void | resetSpaceGroupCharacter () |
void | resetZeroGroupCharacter () |
void | setCharacterSet (const std::array< char, 85 > &set) |
void | setHandlePadding (bool handlePadding) |
void | setSpaceGroupCharacter (const char &ch) |
void | setZeroGroupCharacter (const char &ch) |
std::optional< char > | spaceGroupCharacter () const |
bool | usesSpaceGroupShortcut () const |
bool | usesZeroGroupShortcut () const |
std::optional< char > | zeroGroupCharacter () const |
Static Public Member Functions | |
static bool | characterIsLegal (char ch) |
static const Base85Encoding * | encodingFromStandard (StandardEncoding enc) |
All Base85 codecs fundamentally operate by converting between 4-byte chunks of binary data and 5-character chunks of ASCII text; however, the specifics of that conversion can vary depending on the particular Base85 implementation. This class allows for fine tuning these parameters when encoding/decoding a Base85.
A Base85 encoding consists of a character set containing exactly 85 characters from for the ASCII character set, along with several optional extensions.
Technically, it is possible to use any character code between 0
and 255
, though "Extended ASCII" (codes above 127
) is not a standardized format and as such would lead to inconsistent renderings of encoded strings between various software/systems even though they would still encode/decode correctly. Therefore, only standard ASCII characters are formally allowed.
There are further restrictions on which characters may be used in an encoding for technical reasons. Whitespace characters, specifically 0x09
('\t'), 0x0A
('\n'), 0x0B
('\v'), 0x0C
('\f'), 0x0D
('\r') and 0x20
(' '), are always ignored while decoding a Base85 string, and as such cannot be part of a character set. Additionally, ASCII control characters (0x00
- 0x1F
and 0x7F
) may evidently be interpreted as commands by many parsers, making their use in a character set impractical without extreme care.
Extension | Effect | Controlled By |
---|---|---|
Zero Group | All zero (0x00000000 ) binary frames will be encoded as a single special character | setZeroGroupCharacter() resetZeroGroupCharacter() |
Space Group | All 'space' (0x20202020 ) binary frames will be encoded as a single special character | setSpaceGroupCharacter() resetSpaceGroupCharacter() |
Padding | Allows for, and enables the automatic handling of padding during encoding/decoding where necessary | setHandlePadding() |
Several standard encodings are provided by this class and can be accessed by the static function encodingFromStandard().
Encoding | Character Set | Zero Group Character | Space Group Character | Supports Padding |
---|---|---|---|---|
btoa | Original | 0x7A ('z') | No | No |
btoa 4.2 | Original | 0x7A ('z') | 0x79 ('y') | No |
Adobe | Original | 0x7A ('z') | No | Yes |
Z85 | Z85 | No | No | No |
RFC 1924 | RFC 1924 | No | No | No |
The 'Original' character set is ASCII 0x21
('!') through 0x75
('u'). For the other character sets, see their parent encodings' specification pages.
This enum specifies the different standard Base85 encodings that are available.
Enumerator | |
---|---|
Btoa | The original Base85 encoding developed by Paul E. Rutter for the 'btoa' utility. |
Btoa_4_2 | The updated version of the original encoding for btoa 4.2. |
Adobe | Adobe's variant of Base85, named Ascii85. |
Z85 | A variant optimized for usability, particular in source code. |
Rfc_1924 | A variant designed as an alternate representation for IPV6 addresses. |
Qx::Base85Encoding::Base85Encoding | ( | ) |
Constructs an invalid Base85 encoding.
This acts as a base for creating a custom encoding.
Qx::Base85Encoding::Base85Encoding | ( | StandardEncoding | enc | ) |
Constructs a new Base85 encoding, copied from the standard encoding specified by enc.
This is useful to create a slightly modified standard encoding, or custom encoding that uses the character set of a standard one.
char Qx::Base85Encoding::characterAt | ( | int | i | ) | const |
Returns the character from the encoding's character set at position i, or 0x00
('\0') if i is out of bounds.
|
static |
Returns true
if ch is a legal character for a Base85 character set; otherwise, returns false
.
int Qx::Base85Encoding::characterPosition | ( | char | ch | ) | const |
Returns the position of character ch within the encoding's character set, or -1
if the character set does not contain that character.
const std::array< char, 85 > & Qx::Base85Encoding::characterSet | ( | ) | const |
Returns the encoding's character set.
bool Qx::Base85Encoding::containsCharacter | ( | char | ch, |
bool | shortcut = true ) const |
Returns true
if the encoding's character set contains ch; otherwise, returns false
.
If shortcut is true
, the encoding's shortcut characters are also checked for a match.
|
static |
Returns a pointer to the standard encoding specified by enc.
bool Qx::Base85Encoding::isHandlePadding | ( | ) | const |
Returns true
if the encoding allows for, and automatically handles padding; otherwise, returns false
.
bool Qx::Base85Encoding::isValid | ( | ) | const |
Returns true
if the encoding is valid; otherwise, returns false
.
An encoding is valid if its character set is composed entirely of unique, legal characters, and its zero group character and space group character are not present in its character set, if the encoding uses them.
The only characters that are strictly illegal for Base85 encoding are the whitespace characters, 0x09
('\t'), 0x0A
('\n'), 0x0B
('\v'), 0x0C
('\f'), 0x0D
('\r') and 0x20
(' ').
bool Qx::Base85Encoding::operator!= | ( | const Base85Encoding & | other | ) | const |
Returns true
if this encoding and other encoding do not use the same parameters; otherwise, returns false
.
bool Qx::Base85Encoding::operator== | ( | const Base85Encoding & | other | ) | const |
Returns true
if this encoding and other encoding use the same parameters; otherwise, returns false
.
void Qx::Base85Encoding::resetSpaceGroupCharacter | ( | ) |
Removes the space group character from the encoding and disables use of the space group shortcut.
void Qx::Base85Encoding::resetZeroGroupCharacter | ( | ) |
Removes the zero group character from the encoding and disables use of the zero group shortcut.
void Qx::Base85Encoding::setCharacterSet | ( | const std::array< char, 85 > & | set | ) |
Sets the character set of the encoding to set.
void Qx::Base85Encoding::setHandlePadding | ( | bool | handlePadding | ) |
Sets whether or not the encoding allows for, and automatically handles padding input data that is not a multiple of 4 bytes when encoding, and output data that is not a multiple or 5 characters when decoding.
void Qx::Base85Encoding::setSpaceGroupCharacter | ( | const char & | ch | ) |
Sets the space group character of the encoding to ch.
This will cause the encoding to use this character as a shortcut when encoding a byte group of all 0x20
instead of the usual set of 5 characters associated with that value.
void Qx::Base85Encoding::setZeroGroupCharacter | ( | const char & | ch | ) |
Sets the zero group character of the encoding to ch.
This will cause the encoding to use this character as a shortcut when encoding a byte group of all 0x00
instead of the usual set of 5 characters associated with that value.
std::optional< char > Qx::Base85Encoding::spaceGroupCharacter | ( | ) | const |
Returns the an optional object that contains the encoding's space group character, if it features one.
bool Qx::Base85Encoding::usesSpaceGroupShortcut | ( | ) | const |
Returns true
if the encoding utilizes a single extra character as a shortcut for representing an all 'space' byte group; otherwise, returns false
.
bool Qx::Base85Encoding::usesZeroGroupShortcut | ( | ) | const |
Returns true
if the encoding utilizes a single extra character as a shortcut for representing an all zero byte group; otherwise, returns false
.
std::optional< char > Qx::Base85Encoding::zeroGroupCharacter | ( | ) | const |
Returns the an optional object that contains the encoding's zero group character, if it features one.