/src/qpdf/libqpdf/QPDFExc.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include <qpdf/QPDFExc.hh> |
2 | | |
3 | | QPDFExc::QPDFExc( |
4 | | qpdf_error_code_e error_code, |
5 | | std::string const& filename, |
6 | | std::string const& object, |
7 | | qpdf_offset_t offset, |
8 | | std::string const& message) : |
9 | 434k | std::runtime_error(createWhat(filename, object, (offset ? offset : -1), message)), |
10 | 434k | error_code(error_code), |
11 | 434k | filename(filename), |
12 | 434k | object(object), |
13 | 434k | offset(offset ? offset : -1), |
14 | 434k | message(message) |
15 | 434k | { |
16 | 434k | } |
17 | | |
18 | | QPDFExc::QPDFExc( |
19 | | qpdf_error_code_e error_code, |
20 | | std::string const& filename, |
21 | | std::string const& object, |
22 | | qpdf_offset_t offset, |
23 | | std::string const& message, |
24 | | bool zero_offset_valid) : |
25 | 334k | std::runtime_error( |
26 | 334k | createWhat(filename, object, (offset || zero_offset_valid ? offset : -1), message)), |
27 | 334k | error_code(error_code), |
28 | 334k | filename(filename), |
29 | 334k | object(object), |
30 | 334k | offset(offset || zero_offset_valid ? offset : -1), |
31 | 334k | message(message) |
32 | 334k | { |
33 | 334k | } |
34 | | |
35 | | std::string |
36 | | QPDFExc::createWhat( |
37 | | std::string const& filename, |
38 | | std::string const& object, |
39 | | qpdf_offset_t offset, |
40 | | std::string const& message) |
41 | 768k | { |
42 | 768k | std::string result; |
43 | 768k | if (!filename.empty()) { |
44 | 695k | result += filename; |
45 | 695k | } |
46 | 768k | if (!(object.empty() && offset < 0)) { |
47 | 658k | if (!filename.empty()) { |
48 | 585k | result += " ("; |
49 | 585k | } |
50 | 658k | if (!object.empty()) { |
51 | 619k | result += object; |
52 | 619k | if (offset >= 0) { |
53 | 546k | result += ", "; |
54 | 546k | } |
55 | 619k | } |
56 | 658k | if (offset >= 0) { |
57 | 584k | result += "offset " + std::to_string(offset); |
58 | 584k | } |
59 | 658k | if (!filename.empty()) { |
60 | 585k | result += ")"; |
61 | 585k | } |
62 | 658k | } |
63 | 768k | if (!result.empty()) { |
64 | 768k | result += ": "; |
65 | 768k | } |
66 | 768k | result += message; |
67 | 768k | return result; |
68 | 768k | } |
69 | | |
70 | | qpdf_error_code_e |
71 | | QPDFExc::getErrorCode() const |
72 | 0 | { |
73 | 0 | return this->error_code; |
74 | 0 | } |
75 | | |
76 | | std::string const& |
77 | | QPDFExc::getFilename() const |
78 | 0 | { |
79 | 0 | return this->filename; |
80 | 0 | } |
81 | | |
82 | | std::string const& |
83 | | QPDFExc::getObject() const |
84 | 0 | { |
85 | 0 | return this->object; |
86 | 0 | } |
87 | | |
88 | | qpdf_offset_t |
89 | | QPDFExc::getFilePosition() const |
90 | 0 | { |
91 | 0 | return offset < 0 ? 0 : offset; |
92 | 0 | } |
93 | | |
94 | | std::string const& |
95 | | QPDFExc::getMessageDetail() const |
96 | 0 | { |
97 | 0 | return this->message; |
98 | 0 | } |