/src/qpdf/libqpdf/QPDF_Real.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include <qpdf/QPDF_Real.hh> |
2 | | |
3 | | #include <qpdf/JSON_writer.hh> |
4 | | #include <qpdf/QUtil.hh> |
5 | | |
6 | | QPDF_Real::QPDF_Real(std::string const& val) : |
7 | | QPDFValue(::ot_real), |
8 | | val(val) |
9 | 73.3k | { |
10 | 73.3k | } |
11 | | |
12 | | QPDF_Real::QPDF_Real(double value, int decimal_places, bool trim_trailing_zeroes) : |
13 | | QPDFValue(::ot_real), |
14 | | val(QUtil::double_to_string(value, decimal_places, trim_trailing_zeroes)) |
15 | 11.4k | { |
16 | 11.4k | } |
17 | | |
18 | | std::shared_ptr<QPDFObject> |
19 | | QPDF_Real::create(std::string const& val) |
20 | 73.3k | { |
21 | 73.3k | return do_create(new QPDF_Real(val)); |
22 | 73.3k | } |
23 | | |
24 | | std::shared_ptr<QPDFObject> |
25 | | QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes) |
26 | 11.4k | { |
27 | 11.4k | return do_create(new QPDF_Real(value, decimal_places, trim_trailing_zeroes)); |
28 | 11.4k | } |
29 | | |
30 | | std::shared_ptr<QPDFObject> |
31 | | QPDF_Real::copy(bool shallow) |
32 | 1.48k | { |
33 | 1.48k | return create(val); |
34 | 1.48k | } |
35 | | |
36 | | std::string |
37 | | QPDF_Real::unparse() |
38 | 95.2k | { |
39 | 95.2k | return this->val; |
40 | 95.2k | } |
41 | | |
42 | | void |
43 | | QPDF_Real::writeJSON(int json_version, JSON::Writer& p) |
44 | 0 | { |
45 | 0 | if (this->val.length() == 0) { |
46 | | // Can't really happen... |
47 | 0 | p << "0"; |
48 | 0 | } else if (this->val.at(0) == '.') { |
49 | 0 | p << "0" << this->val; |
50 | 0 | } else if (this->val.length() >= 2 && this->val.at(0) == '-' && this->val.at(1) == '.') { |
51 | 0 | p << "-0." << this->val.substr(2); |
52 | 0 | } else { |
53 | 0 | p << this->val; |
54 | 0 | } |
55 | 0 | if (val.back() == '.') { |
56 | 0 | p << "0"; |
57 | 0 | } |
58 | 0 | } |