diff options
author | Jay Berkenbilt <ejb@ql.org> | 2024-02-17 20:15:48 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2024-02-17 20:15:48 +0100 |
commit | e362bce8e86f4912eaa008bac06f9e2c19b72d3f (patch) | |
tree | 42fcd9eed699714f98ddee634763e4d670a2652b /libqpdf/QPDF_Real.cc | |
parent | 5a29b7f9dd353c7baf2ca738bd2a56582a6525ea (diff) | |
parent | 413aba5bf2ef239d3abf024de3c819e153171035 (diff) | |
download | qpdf-e362bce8e86f4912eaa008bac06f9e2c19b72d3f.tar.zst |
Merge branch 'jw' from #1146 into work
Diffstat (limited to 'libqpdf/QPDF_Real.cc')
-rw-r--r-- | libqpdf/QPDF_Real.cc | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc index 1d954dcd..f4304397 100644 --- a/libqpdf/QPDF_Real.cc +++ b/libqpdf/QPDF_Real.cc @@ -1,5 +1,6 @@ #include <qpdf/QPDF_Real.hh> +#include <qpdf/JSON_writer.hh> #include <qpdf/QUtil.hh> QPDF_Real::QPDF_Real(std::string const& val) : @@ -38,21 +39,17 @@ QPDF_Real::unparse() return this->val; } -JSON -QPDF_Real::getJSON(int json_version) +void +QPDF_Real::writeJSON(int json_version, JSON::Writer& p) { - // While PDF allows .x or -.x, JSON does not. Rather than converting from string to double and - // back, just handle this as a special case for JSON. - std::string result; if (this->val.length() == 0) { // Can't really happen... - result = "0"; + p << "0"; } else if (this->val.at(0) == '.') { - result = "0" + this->val; - } else if ((this->val.length() >= 2) && (this->val.at(0) == '-') && (this->val.at(1) == '.')) { - result = "-0." + this->val.substr(2); + p << "0" << this->val; + } else if (this->val.length() >= 2 && this->val.at(0) == '-' && this->val.at(1) == '.') { + p << "-0." << this->val.substr(2); } else { - result = this->val; + p << this->val; } - return JSON::makeNumber(result); } |