Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::Base85Encoding Class Reference

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 Base85EncodingencodingFromStandard (StandardEncoding enc)
 

Detailed Description

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.

Character Set:

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.

Extensions:
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()
Standard Encodings:

Several standard encodings are provided by this class and can be accessed by the static function encodingFromStandard().

Standard Encoding Properties
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.

Custom Encodings:
Custom encodings can be created from scratch by constructing a blank encoding via Base85Encoding() and then setting its parameters, or by modifying standard encodings via Base85Encoding(StandardEncoding).

Member Enumeration Documentation

◆ StandardEncoding

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.

Constructor & Destructor Documentation

◆ Base85Encoding() [1/2]

Qx::Base85Encoding::Base85Encoding ( )

Constructs an invalid Base85 encoding.

This acts as a base for creating a custom encoding.

◆ Base85Encoding() [2/2]

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.

See also
encodingFromStandard().

Member Function Documentation

◆ characterAt()

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.

See also
characterPosition().

◆ characterIsLegal()

bool Qx::Base85Encoding::characterIsLegal ( char ch)
static

Returns true if ch is a legal character for a Base85 character set; otherwise, returns false.

◆ characterPosition()

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.

See also
characterAt().

◆ characterSet()

const std::array< char, 85 > & Qx::Base85Encoding::characterSet ( ) const

Returns the encoding's character set.

See also
setCharacterSet().

◆ containsCharacter()

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.

◆ encodingFromStandard()

const Base85Encoding * Qx::Base85Encoding::encodingFromStandard ( StandardEncoding enc)
static

Returns a pointer to the standard encoding specified by enc.

See also
Base85Encoding(StandardEncoding).

◆ isHandlePadding()

bool Qx::Base85Encoding::isHandlePadding ( ) const

Returns true if the encoding allows for, and automatically handles padding; otherwise, returns false.

See also
setHandlePadding().

◆ isValid()

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 (' ').

See also
characterIsLegal(), zeroGroupCharacter(), and spaceGroupCharacter().

◆ operator!=()

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.

◆ operator==()

bool Qx::Base85Encoding::operator== ( const Base85Encoding & other) const

Returns true if this encoding and other encoding use the same parameters; otherwise, returns false.

◆ resetSpaceGroupCharacter()

void Qx::Base85Encoding::resetSpaceGroupCharacter ( )

Removes the space group character from the encoding and disables use of the space group shortcut.

See also
setSpaceGroupCharacter().

◆ resetZeroGroupCharacter()

void Qx::Base85Encoding::resetZeroGroupCharacter ( )

Removes the zero group character from the encoding and disables use of the zero group shortcut.

See also
setZeroGroupCharacter().

◆ setCharacterSet()

void Qx::Base85Encoding::setCharacterSet ( const std::array< char, 85 > & set)

Sets the character set of the encoding to set.

See also
characterSet().

◆ setHandlePadding()

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.

See also
isHandlePadding().

◆ setSpaceGroupCharacter()

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.

See also
spaceGroupCharacter(), usesSpaceGroupShortcut(), resetSpaceGroupCharacter().

◆ setZeroGroupCharacter()

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.

See also
zeroGroupCharacter(), usesZeroGroupShortcut(), resetZeroGroupCharacter().

◆ spaceGroupCharacter()

std::optional< char > Qx::Base85Encoding::spaceGroupCharacter ( ) const

Returns the an optional object that contains the encoding's space group character, if it features one.

See also
setSpaceGroupCharacter().

◆ usesSpaceGroupShortcut()

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.

See also
spaceGroupCharacter().

◆ usesZeroGroupShortcut()

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.

See also
zeroGroupCharacter().

◆ zeroGroupCharacter()

std::optional< char > Qx::Base85Encoding::zeroGroupCharacter ( ) const

Returns the an optional object that contains the encoding's zero group character, if it features one.

See also
setZeroGroupCharacter().

The documentation for this class was generated from the following files: