diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2015-12-27 18:39:47 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2015-12-27 18:40:08 +0900 |
| commit | b1132d6b10cd3791b9529d7031d723fd0e2d8215 (patch) | |
| tree | 9ce465b42bf09372118335c7c619bb2b41869eaf /src/base32.h | |
| parent | 4abad2f64c9ff80144a61c5a9c2bea144852b883 (diff) | |
make clang-format using clang-format-3.6
Diffstat (limited to 'src/base32.h')
| -rw-r--r-- | src/base32.h | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/base32.h b/src/base32.h index 203bb8b9..4220dead 100644 --- a/src/base32.h +++ b/src/base32.h @@ -47,31 +47,35 @@ namespace base32 { std::string encode(const std::string& src); -template<typename InputIterator> +template <typename InputIterator> std::string decode(InputIterator first, InputIterator last) { std::string ret; - size_t len = last-first; - if(len%8) { + size_t len = last - first; + if (len % 8) { return ret; } bool done = false; - for(; first != last && !done; first += 8) { + for (; first != last && !done; first += 8) { uint64_t buf = 0; size_t bits = 0; - for(size_t i = 0; i < 8; ++i) { - char ch = *(first+i); + for (size_t i = 0; i < 8; ++i) { + char ch = *(first + i); unsigned char value; - if('A' <= ch && ch <= 'Z') { - value = ch-'A'; - } else if('a' <= ch && ch <= 'z') { - value = ch-'a'; - } else if('2' <= ch && ch <= '7') { - value = ch-'2'+26; - } else if(ch == '=') { + if ('A' <= ch && ch <= 'Z') { + value = ch - 'A'; + } + else if ('a' <= ch && ch <= 'z') { + value = ch - 'a'; + } + else if ('2' <= ch && ch <= '7') { + value = ch - '2' + 26; + } + else if (ch == '=') { done = true; break; - } else { + } + else { ret.clear(); return ret; } @@ -79,11 +83,11 @@ std::string decode(InputIterator first, InputIterator last) buf += value; bits += 5; } - buf >>= (bits%8); - bits = bits/8*8; + buf >>= (bits % 8); + bits = bits / 8 * 8; buf = hton64(buf); char* p = reinterpret_cast<char*>(&buf); - ret.append(&p[(64-bits)/8], &p[8]); + ret.append(&p[(64 - bits) / 8], &p[8]); } return ret; } |
