Skip to content

Commit bc3a4a2

Browse files
committed
stdEncode: make prefix and suffix optional
1 parent 7f86f0e commit bc3a4a2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/utility/SElementBase64.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
5656
int b;
5757
String out;
5858

59-
int reserveLength = 4 * ((length + 2) / 3) + ((length / 3 * 4) / 76) + strlen(prefix) + strlen(suffix);
59+
int reserveLength = 4 * ((length + 2) / 3) + ((length / 3 * 4) / 76);
60+
if (prefix != nullptr) {
61+
reserveLength += strlen(prefix);
62+
}
63+
if (suffix != nullptr) {
64+
reserveLength += strlen(suffix);
65+
}
6066
out.reserve(reserveLength);
6167

6268
if (prefix) {

src/utility/SElementBase64.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
namespace arduino { namespace b64 {
1616

1717
String urlEncode(const byte in[], unsigned int length);
18-
String stdEncode(const byte in[], unsigned int length, const char* prefix, const char* suffix);
18+
String stdEncode(const byte in[], unsigned int length, const char* prefix=nullptr, const char* suffix=nullptr);
1919

2020
}} // arduino::b64

0 commit comments

Comments
 (0)