/src/libheif/libheif/logging.cc
Line | Count | Source |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2024 Dirk Farin <dirk.farin@gmail.com> |
4 | | * |
5 | | * This file is part of libheif. |
6 | | * |
7 | | * libheif is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libheif is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libheif. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #include "logging.h" |
22 | | #include <sstream> |
23 | | #include <iomanip> |
24 | | |
25 | | |
26 | | std::string Indent::get_string() const |
27 | 0 | { |
28 | 0 | std::stringstream sstr; |
29 | |
|
30 | 0 | for (int i = 0; i < get_indent(); i++) { |
31 | 0 | sstr << "| "; |
32 | 0 | } |
33 | |
|
34 | 0 | return sstr.str(); |
35 | 0 | } |
36 | | |
37 | | |
38 | | std::string write_raw_data_as_hex(const uint8_t* data, size_t len, |
39 | | const std::string& firstLineIndent, |
40 | | const std::string& remainingLinesIndent) |
41 | 0 | { |
42 | 0 | std::stringstream sstr; |
43 | |
|
44 | 0 | sstr << std::hex << std::setfill('0'); |
45 | |
|
46 | 0 | for (size_t i = 0; i < len; i++) { |
47 | 0 | if (i % 16 == 0) { |
48 | | // start of line |
49 | |
|
50 | 0 | if (i == 0) { |
51 | 0 | sstr << firstLineIndent; |
52 | 0 | } |
53 | 0 | else { |
54 | 0 | sstr << remainingLinesIndent; |
55 | 0 | } |
56 | 0 | sstr << std::setw(4) << i << ": "; // address |
57 | 0 | } |
58 | 0 | else if (i % 16 == 8) { |
59 | | // space in middle |
60 | 0 | sstr << " "; |
61 | 0 | } |
62 | 0 | else { |
63 | | // space between bytes |
64 | 0 | sstr << " "; |
65 | 0 | } |
66 | |
|
67 | 0 | sstr << std::setw(2) << ((int) data[i]); |
68 | |
|
69 | 0 | if (i % 16 == 15 || i == len - 1) { |
70 | 0 | sstr << "\n"; |
71 | 0 | } |
72 | 0 | } |
73 | |
|
74 | 0 | return sstr.str(); |
75 | 0 | } |