13#ifndef LLVM_SUPPORT_BASE64_H
14#define LLVM_SUPPORT_BASE64_H
23template <
class InputBytes> std::string
encodeBase64(InputBytes
const &Bytes) {
24 static const char Table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
25 "abcdefghijklmnopqrstuvwxyz"
28 Buffer.resize(((Bytes.size() + 2) / 3) * 4);
31 for (
size_t n = Bytes.size() / 3 * 3; i < n; i += 3, j += 4) {
33 ((
unsigned char)Bytes[i + 1] << 8) |
34 (
unsigned char)Bytes[i + 2];
35 Buffer[j + 0] = Table[(x >> 18) & 63];
36 Buffer[j + 1] = Table[(x >> 12) & 63];
37 Buffer[j + 2] = Table[(x >> 6) & 63];
38 Buffer[j + 3] = Table[x & 63];
40 if (i + 1 == Bytes.size()) {
42 Buffer[j + 0] = Table[(x >> 18) & 63];
43 Buffer[j + 1] = Table[(x >> 12) & 63];
46 }
else if (i + 2 == Bytes.size()) {
48 ((
unsigned char)Bytes[i] << 16) | ((
unsigned char)Bytes[i + 1] << 8);
49 Buffer[j + 0] = Table[(x >> 18) & 63];
50 Buffer[j + 1] = Table[(x >> 12) & 63];
51 Buffer[j + 2] = Table[(x >> 6) & 63];
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
std::string encodeBase64(InputBytes const &Bytes)
llvm::Error decodeBase64(llvm::StringRef Input, std::vector< char > &Output)