File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -35,15 +35,21 @@ namespace ix
35
35
" 0123456789+/" ;
36
36
37
37
std::string base64_encode (const std::string& data, size_t len)
38
+ {
39
+ const char * bytes_to_encode = data.c_str ();
40
+ return base64_encode (bytes_to_encode, len);
41
+ }
42
+
43
+ std::string base64_encode (const char * bytes_to_encode, size_t len)
38
44
{
39
45
std::string ret;
46
+ ret.reserve (((len + 2 ) / 3 ) * 4 );
47
+
40
48
int i = 0 ;
41
49
int j = 0 ;
42
50
unsigned char char_array_3[3 ];
43
51
unsigned char char_array_4[4 ];
44
52
45
- const char * bytes_to_encode = data.c_str ();
46
-
47
53
while (len--)
48
54
{
49
55
char_array_3[i++] = *(bytes_to_encode++);
@@ -95,6 +101,7 @@ namespace ix
95
101
int in_ = 0 ;
96
102
unsigned char char_array_4[4 ], char_array_3[3 ];
97
103
std::string ret;
104
+ ret.reserve (((in_len + 3 ) / 4 ) * 3 );
98
105
99
106
while (in_len-- && ( encoded_string[in_] != ' =' ) && is_base64 (encoded_string[in_]))
100
107
{
Original file line number Diff line number Diff line change 11
11
namespace ix
12
12
{
13
13
std::string base64_encode (const std::string& data, size_t len);
14
+ std::string base64_encode (const char * data, size_t len);
14
15
std::string base64_decode (const std::string& encoded_string);
15
16
} // namespace ix
You can’t perform that action at this time.
0 commit comments