MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/xstudio / base64_encode

Function base64_encode

extern/include/cpp-httplib/httplib.h:1991–2017  ·  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

1989// NOTE: This code came up with the following stackoverflow post:
1990// https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
1991inline std::string base64_encode(const std::string &in) {
1992 static const auto lookup =
1993 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1994
1995 std::string out;
1996 out.reserve(in.size());
1997
1998 int val = 0;
1999 int valb = -6;
2000
2001 for (auto c : in) {
2002 val = (val << 8) + static_cast<uint8_t>(c);
2003 valb += 8;
2004 while (valb >= 0) {
2005 out.push_back(lookup[(val >> valb) & 0x3F]);
2006 valb -= 6;
2007 }
2008 }
2009
2010 if (valb > -6) { out.push_back(lookup[((val << 8) >> (valb + 8)) & 0x3F]); }
2011
2012 while (out.size() % 4) {
2013 out.push_back('=');
2014 }
2015
2016 return out;
2017}
2018
2019inline bool is_file(const std::string &path) {
2020#ifdef _WIN32

Callers 1

Calls 2

push_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected