Skip to content

Commit 3ca2c00

Browse files
committed
Added string capabilities and fixed bug in decoder.
1 parent 84d47b1 commit 3ca2c00

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

utility/base64.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,40 @@ namespace JSON
5151

5252
explicit Base64Binary (ContainerT <CharType> container)
5353
: binary_(std::move(container))
54-
{ }
54+
{ }
55+
56+
/**
57+
* This constructor does stop on the null terminator '\0' (exclusive).
58+
*/
59+
Base64Binary (const CharType* init)
60+
: binary_()
61+
{
62+
for (auto const* c = init; *c != '\0'; ++c)
63+
binary_.push_back(*c);
64+
}
65+
66+
/**
67+
* Inserts the container contents into a string.
68+
*
69+
* @return A string from the binary data.
70+
*/
71+
std::basic_string <CharType> toString() const
72+
{
73+
return {std::begin(binary_), std::end(binary_)};
74+
}
5575

5676
Base64Binary& operator= (ContainerT <CharType> const& container)
5777
{
5878
binary_ = container;
5979
return *this;
80+
}
81+
82+
Base64Binary& operator= (const CharType* str)
83+
{
84+
binary_.clear();
85+
for (auto const* c = str; *c != '\0'; ++c)
86+
binary_.push_back(*c);
87+
return *this;
6088
}
6189

6290
operator ContainerT <CharType>& () { return binary_; }
@@ -179,7 +207,9 @@ namespace JSON
179207
if (c == '+')
180208
return 62;
181209
if (c == '/')
182-
return 63;
210+
return 63;
211+
if (c == '=')
212+
return 64;
183213
else
184214
throw std::invalid_argument ("input contains characters that are not base64");
185215
return 0;

0 commit comments

Comments
 (0)