1#ifndef MSTL_CORE_ENCRYPT_BASE64_HPP__
2#define MSTL_CORE_ENCRYPT_BASE64_HPP__
3#include "../string/string.hpp"
8 static constexpr auto chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
10 static constexpr int char_to_index(
const char c) {
11 if (c >=
'A' && c <=
'Z')
return c -
'A';
12 if (c >=
'a' && c <=
'z')
return c -
'a' + 26;
13 if (c >=
'0' && c <=
'9')
return c -
'0' + 52;
14 if (c ==
'+')
return 62;
15 if (c ==
'/')
return 63;
20 static string encode(bstring_view
data);
21 static bstring decode(string_view
data);
25MSTL_ALWAYS_INLINE_INLINE
string base64_encode(
const bstring&
data) {
26 return base64::encode(
data.view());
28MSTL_ALWAYS_INLINE_INLINE
string base64_encode(
const string&
data) {
29 return base64_encode(to_bstring(
data));
31MSTL_ALWAYS_INLINE_INLINE
string base64_decode(
const string&
data) {
32 return to_string(base64::decode(
data.view()));
35MSTL_ALWAYS_INLINE_INLINE
string base64_encode(
const bstring_view
data) {
36 return base64::encode(
data);
38MSTL_ALWAYS_INLINE_INLINE
string base64_encode(
const string_view
data) {
39 return base64_encode(to_bstring(
data));
41MSTL_ALWAYS_INLINE_INLINE
string base64_decode(
const string_view
data) {
42 return to_string(base64::decode(
data));
45MSTL_ALWAYS_INLINE_INLINE
string base64_encode(
const char*
data) {
46 return base64_encode(to_bstring(string_view{
data}));
48MSTL_ALWAYS_INLINE_INLINE
string base64_decode(
const char*
data) {
49 return to_string(base64::decode(string_view{
data}));
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针