5#include "qx/core/qx_core_export.h"
8#include "qx/core/qx-char.h"
21using namespace Qt::Literals::StringLiterals;
41 static constexpr std::array<char, 85> CHAR_SET_DEFAULT = [](){
42 std::array<char, 85> arr;
46 static constexpr std::array<char, 85> CHAR_SET_ORIGINAL = [](){
47 char asciiValue = 0x21;
48 std::array<char, 85> arr;
49 for(
auto itr = arr.begin(); itr != arr.end(); itr++)
53 static constexpr std::array<char, 85> CHAR_SET_Z85{
54 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
55 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
56 'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
57 'u',
'v',
'w',
'x',
'y',
'z',
'A',
'B',
'C',
'D',
58 'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
59 'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
60 'Y',
'Z',
'.',
'-',
':',
'+',
'=',
'^',
'!',
'/',
61 '*',
'?',
'&',
'<',
'>',
'(',
')',
'[',
']',
'{',
62 '}',
'@',
'%',
'$',
'#'
64 static constexpr std::array<char, 85> CHAR_SET_RFC_1924{
65 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
66 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
67 'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
68 'U',
'V',
'W',
'X',
'Y',
'Z',
'a',
'b',
'c',
'd',
69 'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
70 'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
71 'y',
'z',
'!',
'#',
'$',
'%',
'&',
'(',
')',
'*',
72 '+',
'-',
';',
'<',
'=',
'>',
'?',
'@',
'^',
'_',
73 '`',
'{',
'|',
'}',
'~'
75 static constexpr char ZERO_GROUP_CHAR_ORIGINAL =
'z';
76 static constexpr char SPACE_GROUP_CHAR_ORIGINAL =
'y';
79 static inline QHash<StandardEncoding, Base85Encoding> smStdEncodings;
82 static inline const QSet<char> ILLEGAL_CHAR_SET = {
'\x09',
'\x0A',
'\x0B',
'\x0C',
'\x0D',
'\x20'};
87 std::array<char, 85> mCharSet;
88 QHash<char, int> mDecodeMap;
89 std::optional<char> mZeroGroupChar;
90 std::optional<char> mSpaceGroupChar;
96 Base85Encoding(StandardEncoding enc);
100 static const QHash<char, int>& decodeMapOriginalSet();
101 static const QHash<char, int>& decodeMapZ85Set();
102 static const QHash<char, int>& decodeMapRfc1924Set();
104 static bool characterIsLegal(
char ch);
105 static const Base85Encoding* encodingFromStandard(StandardEncoding enc);
109 void generateDecodeMap();
110 void evaluateValidity();
113 bool isValid()
const;
114 const std::array<char, 85>& characterSet()
const;
115 std::optional<char> zeroGroupCharacter()
const;
116 std::optional<char> spaceGroupCharacter()
const;
117 bool isHandlePadding()
const;
118 bool usesZeroGroupShortcut()
const;
119 bool usesSpaceGroupShortcut()
const;
121 char characterAt(
int i)
const;
122 int characterPosition(
char ch)
const;
123 bool containsCharacter(
char ch,
bool shortcut =
true)
const;
125 void setCharacterSet(
const std::array<char, 85>& set);
126 void setZeroGroupCharacter(
const char& ch);
127 void setSpaceGroupCharacter(
const char& ch);
128 void resetZeroGroupCharacter();
129 void resetSpaceGroupCharacter();
130 void setHandlePadding(
bool handlePadding);
132 bool operator==(
const Base85Encoding& other)
const;
133 bool operator!=(
const Base85Encoding& other)
const;
151 static inline const QHash<ParseError, QString> ERROR_STR_MAP{
152 {NoError, u
"No error occurred."_s},
153 {InvalidEncoding, u
"The provided encoding is invalid."_s},
154 {PaddingRequired, u
"The string makes use of padding, but the specified encoding does not support padding."_s},
155 {NonANSI, u
"The string contains characters that are wider than a single byte."_s},
156 {CharacterSetMismatch, u
"The string contains characters that are not present in the specified encoding's character set."_s},
157 {ShortcutMidFrame, u
"A shortcut character appears in the middle of one of the string's 5-character ASCII frames."_s},
168 Base85ParseError(ParseError error, qsizetype offset);
172 ParseError error()
const;
173 QString errorString()
const;
174 qsizetype offset()
const;
177class QX_CORE_EXPORT Base85
182 static constexpr char ENCODE_PAD_CHAR =
'\0';
185 static inline const QByteArray ZERO_GROUP_FRAME =
"\x00\x00\x00\x00"_ba;
186 static inline const QByteArray SPACE_GROUP_FRAME =
"\x20\x20\x20\x20"_ba;
189 static constexpr quint32 POWERS_OF_85[] = {
211 static void encodeData(
const QByteArray&
data, Base85& encoded);
217 static char charToLatin1(
char ch);
218 static char charToLatin1(QChar ch);
242 QByteArrayView
data()
const;
243 qsizetype
size()
const;
The Base85Encoding class provides the parameters of a particular Base85 string encoding.
Definition qx-base85.h:27
StandardEncoding
Definition qx-base85.h:30
@ Adobe
Definition qx-base85.h:33
@ Btoa
Definition qx-base85.h:31
@ Btoa_4_2
Definition qx-base85.h:32
@ Rfc_1924
Definition qx-base85.h:35
@ Z85
Definition qx-base85.h:34
Base85Encoding()
Definition qx-base85.cpp:128
The Base85ParseError class is used to report errors while parsing a Base85 encoded string.
Definition qx-base85.h:137
ParseError
Definition qx-base85.h:140
@ InvalidEncoding
Definition qx-base85.h:142
@ NoError
Definition qx-base85.h:141
@ PaddingRequired
Definition qx-base85.h:143
@ CharacterSetMismatch
Definition qx-base85.h:145
@ ShortcutMidFrame
Definition qx-base85.h:146
@ NonANSI
Definition qx-base85.h:144
Base85ParseError()
Definition qx-base85.cpp:556
const Base85Encoding * encoding() const
Definition qx-base85.cpp:1023
static Base85 fromEncoded(QAnyStringView base85, const Base85Encoding *enc, Base85ParseError *error=nullptr)
Definition qx-base85.cpp:968
bool isEmpty()
Definition qx-base85.cpp:1016
bool isNull()
Definition qx-base85.cpp:1009
QString toString()
Definition qx-base85.cpp:1048
static Base85 encode(const QByteArray &data, const Base85Encoding *enc)
Definition qx-base85.cpp:982
qsizetype size() const
Definition qx-base85.cpp:1060
bool operator==(const Base85 &other) const
Definition qx-base85.cpp:1067
QByteArrayView data() const
Definition qx-base85.cpp:1055
QByteArray decode()
Definition qx-base85.cpp:1031
bool operator!=(const Base85 &other) const
Definition qx-base85.cpp:1078
Specifies that a type is one of several types.
Definition qx-concepts.h:509
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-abstracterror.cpp:13
SqlString operator!=(const SqlString &s, const Qx::SqlQuery &q)
Definition qx-sqlstring.cpp:204
SqlString operator==(const SqlString &s, const Qx::SqlQuery &q)
Definition qx-sqlstring.cpp:199
The qx-concepts header file provides a library of general purpose concepts as an extension of the sta...