diff options
Diffstat (limited to 'src/libs/3rdparty/yaml-cpp/src/binary.cpp')
-rw-r--r-- | src/libs/3rdparty/yaml-cpp/src/binary.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/libs/3rdparty/yaml-cpp/src/binary.cpp b/src/libs/3rdparty/yaml-cpp/src/binary.cpp index a7e51301b8..d27762a243 100644 --- a/src/libs/3rdparty/yaml-cpp/src/binary.cpp +++ b/src/libs/3rdparty/yaml-cpp/src/binary.cpp @@ -1,5 +1,7 @@ #include "yaml-cpp/binary.h" +#include <cctype> + namespace YAML { static const char encoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -64,7 +66,7 @@ static const unsigned char decoding[] = { }; std::vector<unsigned char> DecodeBase64(const std::string &input) { - typedef std::vector<unsigned char> ret_type; + using ret_type = std::vector<unsigned char>; if (input.empty()) return ret_type(); @@ -72,22 +74,27 @@ std::vector<unsigned char> DecodeBase64(const std::string &input) { unsigned char *out = &ret[0]; unsigned value = 0; - for (std::size_t i = 0; i < input.size(); i++) { - unsigned char d = decoding[static_cast<unsigned>(input[i])]; + for (std::size_t i = 0, cnt = 0; i < input.size(); i++) { + if (std::isspace(static_cast<unsigned char>(input[i]))) { + // skip newlines + continue; + } + unsigned char d = decoding[static_cast<unsigned char>(input[i])]; if (d == 255) return ret_type(); value = (value << 6) | d; - if (i % 4 == 3) { + if (cnt % 4 == 3) { *out++ = value >> 16; if (i > 0 && input[i - 1] != '=') *out++ = value >> 8; if (input[i] != '=') *out++ = value; } + ++cnt; } ret.resize(out - &ret[0]); return ret; } -} +} // namespace YAML |