src/detail/base64.cpp
91.7% Lines (22/24)
100.0% List of functions (1/1)
88.9% Branches (8/9)
Functions (1)
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2026 Mohammad Nejati | |||
| 3 | // | |||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 6 | // | |||
| 7 | // Official repository: https://github.com/cppalliance/burl | |||
| 8 | // | |||
| 9 | ||||
| 10 | #include "base64.hpp" | |||
| 11 | ||||
| 12 | namespace boost | |||
| 13 | { | |||
| 14 | namespace burl | |||
| 15 | { | |||
| 16 | namespace detail | |||
| 17 | { | |||
| 18 | ||||
| 19 | void | |||
| 20 | 12x | base64_encode(std::string& dest, std::string_view src) | ||
| 21 | { | |||
| 22 | // Adapted from Boost.Beast project | |||
| 23 | 12x | char const* in = src.data(); | ||
| 24 | static char constexpr tab[] = { | |||
| 25 | "ABCDEFGHIJKLMNOP" | |||
| 26 | "QRSTUVWXYZabcdef" | |||
| 27 | "ghijklmnopqrstuv" | |||
| 28 | "wxyz0123456789+/" | |||
| 29 | }; | |||
| 30 | ||||
| 31 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 12 times.
|
28x | for(auto n = src.size() / 3; n--;) | |
| 32 | { | |||
| 33 | ✗ | dest.append({ | ||
| 34 | 16x | tab[(in[0] & 0xfc) >> 2], | ||
| 35 | 16x | tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)], | ||
| 36 | 16x | tab[((in[2] & 0xc0) >> 6) + ((in[1] & 0x0f) << 2)], | ||
| 37 |
1/1✓ Branch 1 taken 16 times.
|
16x | tab[in[2] & 0x3f] }); | |
| 38 | 16x | in += 3; | ||
| 39 | } | |||
| 40 | ||||
| 41 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
|
12x | switch(src.size() % 3) | |
| 42 | { | |||
| 43 | 2x | case 2: | ||
| 44 | ✗ | dest.append({ | ||
| 45 | 2x | tab[ (in[0] & 0xfc) >> 2], | ||
| 46 | 2x | tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)], | ||
| 47 |
1/1✓ Branch 1 taken 2 times.
|
2x | tab[ (in[1] & 0x0f) << 2], | |
| 48 | '=' }); | |||
| 49 | 2x | break; | ||
| 50 | 2x | case 1: | ||
| 51 | 4x | dest.append({ | ||
| 52 | 2x | tab[ (in[0] & 0xfc) >> 2], | ||
| 53 |
1/1✓ Branch 1 taken 2 times.
|
2x | tab[((in[0] & 0x03) << 4)], | |
| 54 | '=', | |||
| 55 | '=' }); | |||
| 56 | 2x | break; | ||
| 57 | 8x | case 0: | ||
| 58 | 8x | break; | ||
| 59 | } | |||
| 60 | 12x | } | ||
| 61 | ||||
| 62 | } // namespace detail | |||
| 63 | } // namespace burl | |||
| 64 | } // namespace boost | |||
| 65 |