Mercurial > hg > orthanc
changeset 3329:98cd69135999
fix base64 static init
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 21 Mar 2019 12:04:39 +0100 |
parents | f0c92ecd09c8 |
children | 10e2b9f4162f |
files | Resources/ThirdParty/base64/base64.cpp |
diffstat | 1 files changed, 23 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/Resources/ThirdParty/base64/base64.cpp Thu Mar 21 11:44:21 2019 +0100 +++ b/Resources/ThirdParty/base64/base64.cpp Thu Mar 21 12:04:39 2019 +0100 @@ -134,19 +134,34 @@ // note that the encoding algorithm from this page was slower (and bugged !) // this code is not using std::vector::find -static std::vector<int> decode_indexes; +// static init equivalent to: +// decode_indexes.assign(256, -1); +// for (int i=0; i<64; ++i) +// decode_indexes[base64_chars[i]] = i; + +static const int decode_indexes[] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; void base64_decode(std::string& result, const std::string &stringToDecode) { result.reserve(result.size() + stringToDecode.size() * 3 / 4 + 10); - if (decode_indexes.size() != 256) // initialize the first time we pass here - { - decode_indexes.assign(256, -1); - for (int i=0; i<64; ++i) - decode_indexes[base64_chars[i]] = i; - } - int val=0, valb=-8; for (std::string::const_iterator c = stringToDecode.begin(); c != stringToDecode.end(); ++c) { if (decode_indexes[*c] == -1)