Mirrors V8's Uint8Array.fromBase64 (TC39-aligned): - last_chunk_handling_options::loose accepts inputs without '=' padding - decode_up_to_bad_char mirrors V8's ArrayBufferFromBase64 - base64_default_or_url accepts both standard (+/) and URL-safe (-_) alphabets
| 28 | // - decode_up_to_bad_char mirrors V8's ArrayBufferFromBase64 |
| 29 | // - base64_default_or_url accepts both standard (+/) and URL-safe (-_) alphabets |
| 30 | std::string decodeBase64(const std::string& input) { |
| 31 | size_t max_len = simdutf::maximal_binary_length_from_base64(input.data(), input.size()); |
| 32 | std::string result(max_len, '\0'); |
| 33 | size_t out_len = max_len; |
| 34 | auto r = simdutf::base64_to_binary_safe( |
| 35 | input.data(), input.size(), result.data(), out_len, |
| 36 | simdutf::base64_default_or_url, |
| 37 | simdutf::last_chunk_handling_options::loose, |
| 38 | /*decode_up_to_bad_char*/ true); |
| 39 | if (r.error != simdutf::error_code::SUCCESS) { |
| 40 | throw std::runtime_error("Input is not valid base64-encoded data"); |
| 41 | } |
| 42 | result.resize(out_len); |
| 43 | return result; |
| 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 |
no test coverage detected