MCPcopy Create free account
hub / github.com/VCVRack/Rack / fromBase64

Function fromBase64

src/string.cpp:235–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233
234
235std::vector<uint8_t> fromBase64(const std::string& str) {
236 std::vector<uint8_t> data;
237 uint32_t block = 0;
238 int i = 0;
239 int padding = 0;
240
241 for (char c : str) {
242 uint8_t d = 0;
243
244 if ('A' <= c && c <= 'Z') {
245 d = c - 'A';
246 }
247 else if ('a' <= c && c <= 'z') {
248 d = c - 'a' + 26;
249 }
250 else if ('0' <= c && c <= '9') {
251 d = c - '0' + 52;
252 }
253 else if (c == '+') {
254 d = 62;
255 }
256 else if (c == '/') {
257 d = 63;
258 }
259 else if (c == '=') {
260 padding++;
261 }
262 else {
263 // Ignore whitespace and non-base64 characters
264 continue;
265 }
266
267 block |= uint32_t(d) << (6 * (3 - i));
268 i++;
269
270 if (i >= 4) {
271 // Decode block
272 data.push_back((block >> (8 * (2 - 0))) & 0xff);
273 if (padding < 2)
274 data.push_back((block >> (8 * (2 - 1))) & 0xff);
275 if (padding < 1)
276 data.push_back((block >> (8 * (2 - 2))) & 0xff);
277 // Reset block
278 block = 0;
279 i = 0;
280 padding = 0;
281 }
282 }
283 return data;
284}
285
286
287int strcasecmp(const char* s1, const char* s2) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected