Skip to content

Commit 1b7dc2f

Browse files
More improvements by Pablo Martin-Gomez (2.rc.07)
1 parent 3817f6b commit 1b7dc2f

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ WARNINGS= \
1111
-Winit-self \
1212
-Wlogical-op \
1313
-Wmissing-include-dirs \
14+
-Wmissing-declarations \
1415
-Wnoexcept \
1516
-Wold-style-cast \
1617
-Woverloaded-virtual \

base64.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
More information at
66
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
77
8-
Version: 2.rc.05 (release candidate)
8+
Version: 2.rc.07 (release candidate)
99
1010
Copyright (C) 2004-2017, 2020 René Nyffenegger
1111
@@ -41,7 +41,7 @@
4141
// two sets of base64 characters needs to be chosen.
4242
// They differ in their last two characters.
4343
//
44-
const char* base64_chars[2] = {
44+
static const char* base64_chars[2] = {
4545
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4646
"abcdefghijklmnopqrstuvwxyz"
4747
"0123456789"
@@ -166,24 +166,18 @@ static std::string decode(String encoded_string, bool remove_linebreaks) {
166166
// or std::string_view (requires at least C++17)
167167
//
168168

169-
if (remove_linebreaks) {
169+
if (encoded_string.empty()) return std::string();
170170

171-
if (! encoded_string.length() ) {
172-
return "";
173-
}
171+
if (remove_linebreaks) {
174172

175173
std::string copy(encoded_string);
176174

177175
copy.erase(std::remove(copy.begin(), copy.end(), '\n'), copy.end());
178176

179177
return base64_decode(copy, false);
180-
181178
}
182179

183180
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;
187181
size_t pos = 0;
188182

189183
//
@@ -196,7 +190,7 @@ static std::string decode(String encoded_string, bool remove_linebreaks) {
196190
std::string ret;
197191
ret.reserve(approx_length_of_decoded_string);
198192

199-
while (pos < in_len) {
193+
while (pos < length_of_string) {
200194

201195
unsigned int pos_of_char_1 = pos_of_char(encoded_string[pos+1] );
202196

base64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// base64 encoding and decoding with C++.
3-
// Version: 2.rc.06 (release candidate)
3+
// Version: 2.rc.07 (release candidate)
44
//
55

66
#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A

0 commit comments

Comments
 (0)