Skip to content

Commit

Permalink
More improvements by Pablo Martin-Gomez (2.rc.07)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneNyffenegger committed Oct 23, 2020
1 parent 3817f6b commit 1b7dc2f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ WARNINGS= \
-Winit-self \
-Wlogical-op \
-Wmissing-include-dirs \
-Wmissing-declarations \
-Wnoexcept \
-Wold-style-cast \
-Woverloaded-virtual \
Expand Down
16 changes: 5 additions & 11 deletions base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
More information at
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
Version: 2.rc.05 (release candidate)
Version: 2.rc.07 (release candidate)
Copyright (C) 2004-2017, 2020 René Nyffenegger
Expand Down Expand Up @@ -41,7 +41,7 @@
// two sets of base64 characters needs to be chosen.
// They differ in their last two characters.
//
const char* base64_chars[2] = {
static const char* base64_chars[2] = {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
Expand Down Expand Up @@ -166,24 +166,18 @@ static std::string decode(String encoded_string, bool remove_linebreaks) {
// or std::string_view (requires at least C++17)
//

if (remove_linebreaks) {
if (encoded_string.empty()) return std::string();

if (! encoded_string.length() ) {
return "";
}
if (remove_linebreaks) {

std::string copy(encoded_string);

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

return base64_decode(copy, false);

}

size_t length_of_string = encoded_string.length();
if (!length_of_string) return std::string("");

size_t in_len = length_of_string;
size_t pos = 0;

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

while (pos < in_len) {
while (pos < length_of_string) {

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

Expand Down
2 changes: 1 addition & 1 deletion base64.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// base64 encoding and decoding with C++.
// Version: 2.rc.06 (release candidate)
// Version: 2.rc.07 (release candidate)
//

#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
Expand Down

0 comments on commit 1b7dc2f

Please sign in to comment.