5
5
More information at
6
6
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
7
7
8
- Version: 2.rc.05 (release candidate)
8
+ Version: 2.rc.07 (release candidate)
9
9
10
10
Copyright (C) 2004-2017, 2020 René Nyffenegger
11
11
41
41
// two sets of base64 characters needs to be chosen.
42
42
// They differ in their last two characters.
43
43
//
44
- const char * base64_chars[2 ] = {
44
+ static const char * base64_chars[2 ] = {
45
45
" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
46
46
" abcdefghijklmnopqrstuvwxyz"
47
47
" 0123456789"
@@ -166,24 +166,18 @@ static std::string decode(String encoded_string, bool remove_linebreaks) {
166
166
// or std::string_view (requires at least C++17)
167
167
//
168
168
169
- if (remove_linebreaks) {
169
+ if (encoded_string. empty ()) return std::string ();
170
170
171
- if (! encoded_string.length () ) {
172
- return " " ;
173
- }
171
+ if (remove_linebreaks) {
174
172
175
173
std::string copy (encoded_string);
176
174
177
175
copy.erase (std::remove (copy.begin (), copy.end (), ' \n ' ), copy.end ());
178
176
179
177
return base64_decode (copy, false );
180
-
181
178
}
182
179
183
180
size_t length_of_string = encoded_string.length ();
184
- if (!length_of_string) return std::string (" " );
185
-
186
- size_t in_len = length_of_string;
187
181
size_t pos = 0 ;
188
182
189
183
//
@@ -196,7 +190,7 @@ static std::string decode(String encoded_string, bool remove_linebreaks) {
196
190
std::string ret;
197
191
ret.reserve (approx_length_of_decoded_string);
198
192
199
- while (pos < in_len ) {
193
+ while (pos < length_of_string ) {
200
194
201
195
unsigned int pos_of_char_1 = pos_of_char (encoded_string[pos+1 ] );
202
196
0 commit comments