12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #ifndef CPPCODEC_BASE64_URL
- #define CPPCODEC_BASE64_URL
- #include "detail/codec.hpp"
- #include "detail/base64.hpp"
- namespace cppcodec {
- namespace detail {
- static constexpr const char base64_url_alphabet[] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'
- };
- class base64_url
- {
- public:
- template <typename Codec> using codec_impl = stream_codec<Codec, base64_url>;
- static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
- static_assert(sizeof(base64_url_alphabet) == 64, "base64 alphabet must have 64 values");
- return sizeof(base64_url_alphabet);
- }
- static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
- {
- return base64_url_alphabet[idx];
- }
- static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c) { return c; }
- static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
- static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
- static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
- static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
- static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
-
- static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
- };
- }
- using base64_url = detail::codec<detail::base64<detail::base64_url>>;
- }
- #endif
|