MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
base64.hpp
1#ifndef MSTL_CORE_ENCRYPT_BASE64_HPP__
2#define MSTL_CORE_ENCRYPT_BASE64_HPP__
3#include "../string/string.hpp"
5
6class MSTL_API base64 {
7private:
8 static constexpr auto chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
9
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;
16 return -1;
17 }
18
19public:
20 static string encode(bstring_view data);
21 static bstring decode(string_view data);
22};
23
24
25MSTL_ALWAYS_INLINE_INLINE string base64_encode(const bstring& data) {
26 return base64::encode(data.view());
27}
28MSTL_ALWAYS_INLINE_INLINE string base64_encode(const string& data) {
29 return base64_encode(to_bstring(data));
30}
31MSTL_ALWAYS_INLINE_INLINE string base64_decode(const string& data) {
32 return to_string(base64::decode(data.view()));
33}
34
35MSTL_ALWAYS_INLINE_INLINE string base64_encode(const bstring_view data) {
36 return base64::encode(data);
37}
38MSTL_ALWAYS_INLINE_INLINE string base64_encode(const string_view data) {
39 return base64_encode(to_bstring(data));
40}
41MSTL_ALWAYS_INLINE_INLINE string base64_decode(const string_view data) {
42 return to_string(base64::decode(data));
43}
44
45MSTL_ALWAYS_INLINE_INLINE string base64_encode(const char* data) {
46 return base64_encode(to_bstring(string_view{data}));
47}
48MSTL_ALWAYS_INLINE_INLINE string base64_decode(const char* data) {
49 return to_string(base64::decode(string_view{data}));
50}
51
53#endif // MSTL_CORE_ENCRYPT_BASE64_HPP__
#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()))
获取容器的底层数据指针