From d951a22faf35aabe526de2588006c9381904b137 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 6 Oct 2017 14:37:53 +0200 Subject: Provide definition reader primitive --- src/istream/buffer.cc | 12 ++++++------ src/util/base64.cc | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/istream/buffer.cc b/src/istream/buffer.cc index aaa93ff..26697f4 100644 --- a/src/istream/buffer.cc +++ b/src/istream/buffer.cc @@ -168,27 +168,27 @@ int IstreamBuf::underflow() { // From C++ annotations 8.1.0~pre1, chapter 23. std::streamsize IstreamBuf::xsgetn(char *dest, std::streamsize n) { int nread = 0; - + while ( n ) { if ( !this->in_avail() ) { if ( this->underflow() == EOF ) { break; } } - + int avail = this->in_avail(); - + if (avail > n) { avail = n; } - + std::memcpy(dest + nread, gptr(), avail); this->gbump(avail); - + nread += avail; n -= avail; } - + return nread; } diff --git a/src/util/base64.cc b/src/util/base64.cc index 4e8d0a4..4a4f095 100644 --- a/src/util/base64.cc +++ b/src/util/base64.cc @@ -8,22 +8,22 @@ namespace dictzip { std::size_t base64_decode(const std::string& encoded) { std::vector map(256,-1); - for ( int i = 0; i < 64; ++i ) { + for ( int i = 0; i < 64; ++i ) { map["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; } std::size_t value = 0; - for ( std::uint8_t c : encoded ) { - if ( map[c] == -1 ) { + for ( std::uint8_t c : encoded ) { + if ( map[c] == -1 ) { throw std::invalid_argument("Invalid character in BASE64 string."); } else { value *= 64; value += map[c]; } - } + } - return value; + return value; } } -- cgit v1.2.3