/src/qpdf/libqpdf/QPDFObject.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include <qpdf/QPDFObject_private.hh> |
2 | | |
3 | | std::string |
4 | | QPDFObject::getDescription() |
5 | 4.56k | { |
6 | 4.56k | qpdf_offset_t shift = (getTypeCode() == ::ot_dictionary) ? 2 |
7 | 4.56k | : (getTypeCode() == ::ot_array) ? 1 |
8 | 4.56k | : 0; |
9 | | |
10 | 4.56k | if (object_description) { |
11 | 4.56k | switch (object_description->index()) { |
12 | 4.56k | case 0: |
13 | 4.56k | { |
14 | | // Simple template string |
15 | 4.56k | auto description = std::get<0>(*object_description); |
16 | | |
17 | 4.56k | if (auto pos = description.find("$OG"); pos != std::string::npos) { |
18 | 0 | description.replace(pos, 3, og.unparse(' ')); |
19 | 0 | } |
20 | 4.56k | if (auto pos = description.find("$PO"); pos != std::string::npos) { |
21 | 0 | description.replace(pos, 3, std::to_string(parsed_offset + shift)); |
22 | 0 | } |
23 | 4.56k | return description; |
24 | 0 | } |
25 | 0 | case 1: |
26 | 0 | { |
27 | | // QPDF::JSONReactor generated description |
28 | 0 | auto j_descr = std::get<1>(*object_description); |
29 | 0 | return ( |
30 | 0 | *j_descr.input + (j_descr.object.empty() ? "" : ", " + j_descr.object) + |
31 | 0 | " at offset " + std::to_string(parsed_offset)); |
32 | 0 | } |
33 | 0 | case 2: |
34 | 0 | { |
35 | | // Child object description |
36 | 0 | auto j_descr = std::get<2>(*object_description); |
37 | 0 | std::string result; |
38 | 0 | if (auto p = j_descr.parent.lock()) { |
39 | 0 | result = p->getDescription(); |
40 | 0 | } |
41 | 0 | result += j_descr.static_descr; |
42 | 0 | if (auto pos = result.find("$VD"); pos != std::string::npos) { |
43 | 0 | result.replace(pos, 3, j_descr.var_descr); |
44 | 0 | } |
45 | 0 | return result; |
46 | 0 | } |
47 | 0 | case 3: |
48 | 0 | auto [stream_id, obj_id] = std::get<3>(*object_description); |
49 | 0 | std::string result = qpdf ? qpdf->getFilename() : ""; |
50 | 0 | result += " object stream " + std::to_string(stream_id) + ", object " + |
51 | 0 | std::to_string(obj_id) + " 0 at offset " + std::to_string(parsed_offset + shift); |
52 | 0 | return result; |
53 | 4.56k | } |
54 | | |
55 | 4.56k | } else if (og.isIndirect()) { |
56 | 0 | return "object " + og.unparse(' '); |
57 | 0 | } |
58 | 0 | return {}; |
59 | 4.56k | } |