|
@@ -3,7 +3,7 @@
|
|
|
* Company: Lynar Studios
|
|
|
* E-Mail: webmaster@lynarstudios.com
|
|
|
* Created: 2022-01-03
|
|
|
- * Changed: 2023-02-23
|
|
|
+ * Changed: 2023-05-15
|
|
|
*
|
|
|
* */
|
|
|
|
|
@@ -12,6 +12,7 @@
|
|
|
|
|
|
using ls::std::encoding::Base64;
|
|
|
using std::string;
|
|
|
+using std::string_view;
|
|
|
using std::unordered_map;
|
|
|
using std::vector;
|
|
|
|
|
@@ -25,7 +26,7 @@ string Base64::encode(const string &_sequence)
|
|
|
|
|
|
for (size_t index = 0; index < _sequence.size(); index += 3)
|
|
|
{
|
|
|
- string byteTriple = Base64::_getNextByteTriple(_sequence, index);
|
|
|
+ string_view byteTriple = Base64::_getNextByteTriple(_sequence, index);
|
|
|
encodedString += Base64::_encodeByteTriple(byteTriple);
|
|
|
}
|
|
|
|
|
@@ -38,7 +39,7 @@ string Base64::decode(const string &_sequence)
|
|
|
|
|
|
for (int index{}; index < _sequence.size(); index += 4)
|
|
|
{
|
|
|
- string quadruple = Base64::_getNextByteQuadruple(_sequence, index);
|
|
|
+ string_view quadruple = Base64::_getNextByteQuadruple(string_view{_sequence}, index);
|
|
|
decodedString += Base64::_decodeByteQuadruple(quadruple);
|
|
|
}
|
|
|
|
|
@@ -63,7 +64,7 @@ string Base64::_applyEndingRule(string _encodedString, size_t _sequenceSize)
|
|
|
return _encodedString;
|
|
|
}
|
|
|
|
|
|
-string Base64::_decodeByteQuadruple(const string &_quadruple)
|
|
|
+string Base64::_decodeByteQuadruple(string_view _quadruple)
|
|
|
{
|
|
|
string decodedText{};
|
|
|
uint8_t shiftValue = 16;
|
|
@@ -82,7 +83,7 @@ string Base64::_decodeByteQuadruple(const string &_quadruple)
|
|
|
return decodedText;
|
|
|
}
|
|
|
|
|
|
-string Base64::_encodeByteTriple(const string &_byteTriple)
|
|
|
+string Base64::_encodeByteTriple(string_view _byteTriple)
|
|
|
{
|
|
|
string encodedText{};
|
|
|
uint32_t bitStorage = Base64::_toEncodingBitStorage(_byteTriple);
|
|
@@ -108,17 +109,14 @@ uint32_t Base64::_extractBitSequence(uint32_t _bitMask, uint32_t _bitStorage)
|
|
|
|
|
|
uint32_t Base64::_generateBitMask(uint32_t _maskValue, uint8_t _shiftValue)
|
|
|
{
|
|
|
- if (_shiftValue == 0)
|
|
|
- {
|
|
|
- return _maskValue;
|
|
|
- }
|
|
|
+ uint32_t bitmask = _maskValue << _shiftValue;
|
|
|
|
|
|
- if (_shiftValue < 0)
|
|
|
+ if (_shiftValue == 0)
|
|
|
{
|
|
|
- return _maskValue >> _shiftValue;
|
|
|
+ bitmask = _maskValue;
|
|
|
}
|
|
|
|
|
|
- return _maskValue << _shiftValue;
|
|
|
+ return bitmask;
|
|
|
}
|
|
|
|
|
|
unordered_map<char, uint8_t> Base64::_getDecodingMap()
|
|
@@ -138,12 +136,12 @@ unordered_map<uint8_t, char> Base64::_getEncodingMap()
|
|
|
return encodingMap;
|
|
|
}
|
|
|
|
|
|
-string Base64::_getNextByteQuadruple(const string &_sequence, size_t _index)
|
|
|
+string_view Base64::_getNextByteQuadruple(string_view _sequence, size_t _index)
|
|
|
{
|
|
|
return _sequence.substr(_index, 4);
|
|
|
}
|
|
|
|
|
|
-string Base64::_getNextByteTriple(const string &_sequence, size_t _index)
|
|
|
+string_view Base64::_getNextByteTriple(string_view _sequence, size_t _index)
|
|
|
{
|
|
|
return _sequence.substr(_index, 3);
|
|
|
}
|
|
@@ -153,7 +151,7 @@ void Base64::_mergeBitSequence(uint32_t &_bitStorage, const uint32_t &_bitMask)
|
|
|
_bitStorage = _bitStorage | _bitMask;
|
|
|
}
|
|
|
|
|
|
-uint32_t Base64::_toDecodingBitStorage(const string &_quadruple)
|
|
|
+uint32_t Base64::_toDecodingBitStorage(string_view _quadruple)
|
|
|
{
|
|
|
uint32_t bitStorage{};
|
|
|
uint8_t letterCounter = 1;
|
|
@@ -161,7 +159,7 @@ uint32_t Base64::_toDecodingBitStorage(const string &_quadruple)
|
|
|
|
|
|
for (char letter : _quadruple)
|
|
|
{
|
|
|
- uint32_t bitMask = Base64::_generateBitMask(decodingMap[(char) letter], (4 - letterCounter) * 6); // must be hardcoded - even in case of less than 4 characters, so that conversion is correct
|
|
|
+ uint32_t bitMask = Base64::_generateBitMask(decodingMap[letter], (4 - letterCounter) * 6); // must be hardcoded - even in case of less than 4 characters, so that conversion is correct
|
|
|
Base64::_mergeBitSequence(bitStorage, bitMask);
|
|
|
++letterCounter;
|
|
|
}
|
|
@@ -169,7 +167,7 @@ uint32_t Base64::_toDecodingBitStorage(const string &_quadruple)
|
|
|
return bitStorage;
|
|
|
}
|
|
|
|
|
|
-uint32_t Base64::_toEncodingBitStorage(const string &_triple)
|
|
|
+uint32_t Base64::_toEncodingBitStorage(string_view _triple)
|
|
|
{
|
|
|
uint32_t bitStorage{};
|
|
|
uint8_t shiftValue = 16;
|