Coverage Report

Created: 2024-09-08 06:04

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