MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / base64_encode

Function base64_encode

dependencies/httplib/httplib.h:1938–1964  ·  view source on GitHub ↗

NOTE: This code came up with the following stackoverflow post: https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c

Source from the content-addressed store, hash-verified

1936// NOTE: This code came up with the following stackoverflow post:
1937// https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
1938inline std::string base64_encode(const std::string &in) {
1939 static const auto lookup =
1940 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1941
1942 std::string out;
1943 out.reserve(in.size());
1944
1945 int val = 0;
1946 int valb = -6;
1947
1948 for (auto c : in) {
1949 val = (val << 8) + static_cast<uint8_t>(c);
1950 valb += 8;
1951 while (valb >= 0) {
1952 out.push_back(lookup[(val >> valb) & 0x3F]);
1953 valb -= 6;
1954 }
1955 }
1956
1957 if (valb > -6) { out.push_back(lookup[((val << 8) >> (valb + 8)) & 0x3F]); }
1958
1959 while (out.size() % 4) {
1960 out.push_back('=');
1961 }
1962
1963 return out;
1964}
1965
1966inline bool is_file(const std::string &path) {
1967#ifdef _WIN32

Callers 1

Calls 2

sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected