mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-16 22:34:00 +02:00
Update to v094r38 release.
byuu says: I'll post more detailed changes later, but basically: - fixed Baldur's Gate bug - guess if no flash ROM ID present (fixes Magical Vacation, many many others) - nall cleanups - sfc/cartridge major cleanups - bsxcartridge/"bsx" renamed to mcc/"mcc" after the logic chip it uses (consistency with SGB/ICD2) - ... and more!
This commit is contained in:
70
nall/encode/base64.hpp
Normal file
70
nall/encode/base64.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef NALL_ENCODE_BASE64_HPP
|
||||
#define NALL_ENCODE_BASE64_HPP
|
||||
|
||||
namespace nall { namespace Encode {
|
||||
|
||||
inline auto Base64(const uint8_t* data, unsigned size, const string& format = "MIME") -> string {
|
||||
vector<uint8_t> result;
|
||||
|
||||
char lookup[65];
|
||||
for(unsigned n = 0; n < 26; n++) lookup[ 0 + n] = 'A' + n;
|
||||
for(unsigned n = 0; n < 26; n++) lookup[26 + n] = 'a' + n;
|
||||
for(unsigned n = 0; n < 10; n++) lookup[52 + n] = '0' + n;
|
||||
|
||||
if(format == "MIME") {
|
||||
lookup[62] = '+';
|
||||
lookup[63] = '/';
|
||||
lookup[64] = '=';
|
||||
} else if(format == "URI") {
|
||||
lookup[62] = '-';
|
||||
lookup[63] = '_';
|
||||
lookup[64] = 0;
|
||||
} else return "";
|
||||
|
||||
unsigned overflow = (3 - (size % 3)) % 3; //bytes to round to nearest multiple of 3
|
||||
uint8_t buffer;
|
||||
|
||||
for(unsigned i = 0; i < size; i++) {
|
||||
switch(i % 3) {
|
||||
case 0:
|
||||
buffer = data[i] >> 2;
|
||||
result.append(lookup[buffer]);
|
||||
buffer = (data[i] & 3) << 4;
|
||||
result.append(lookup[buffer]);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
buffer |= data[i] >> 4;
|
||||
result.last() = lookup[buffer];
|
||||
buffer = (data[i] & 15) << 2;
|
||||
result.append(lookup[buffer]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
buffer |= data[i] >> 6;
|
||||
result.last() = lookup[buffer];
|
||||
buffer = (data[i] & 63);
|
||||
result.append(lookup[buffer]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(lookup[64]) {
|
||||
if(overflow >= 1) result.append(lookup[64]);
|
||||
if(overflow >= 2) result.append(lookup[64]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline auto Base64(const vector<uint8_t>& buffer, const string& format = "MIME") -> string {
|
||||
return Base64(buffer.data(), buffer.size(), format);
|
||||
}
|
||||
|
||||
inline auto Base64(const string& text, const string& format = "MIME") -> string {
|
||||
return Base64(text.binary(), text.size(), format);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user