diff options
author | antonyzhilin <antonyzhilin@yandex-team.com> | 2024-07-05 19:56:10 +0300 |
---|---|---|
committer | antonyzhilin <antonyzhilin@yandex-team.com> | 2024-07-05 20:06:51 +0300 |
commit | 92272084057d874f12ce24f5a7950b867f7d50c2 (patch) | |
tree | 80fd973f61edfd5c1961c6dd024096b5f2822a5e /contrib/libs/yaml-cpp/src/binary.cpp | |
parent | ada19b071f15ecd5d6784db9fd710f68bcccf310 (diff) | |
download | ydb-92272084057d874f12ce24f5a7950b867f7d50c2.tar.gz |
feat contrib: update yaml-cpp to 0.8.0
6e6348bacf1f4cc2d24d90954c63619ba9bee1f0
Diffstat (limited to 'contrib/libs/yaml-cpp/src/binary.cpp')
-rw-r--r-- | contrib/libs/yaml-cpp/src/binary.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/contrib/libs/yaml-cpp/src/binary.cpp b/contrib/libs/yaml-cpp/src/binary.cpp index a7e51301b8..d27762a243 100644 --- a/contrib/libs/yaml-cpp/src/binary.cpp +++ b/contrib/libs/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 |