aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_Real.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-03-11 21:21:27 +0100
committerJay Berkenbilt <ejb@ql.org>2019-03-11 21:22:59 +0100
commitda7c2c0ee90104524ed98a2370af0ea70a0f6d0d (patch)
tree6431dbf9d4421bb96cf1b4c2f957bcdc42b983de /libqpdf/QPDF_Real.cc
parentd2260925f07e55de032ea93b50152b637e69049d (diff)
downloadqpdf-da7c2c0ee90104524ed98a2370af0ea70a0f6d0d.tar.zst
Fix json serialization for {x | -1 < x < 1} (fixes #308)
JSON serialization was preserving the value as presented, but JSON doesn't accept decimal values without a 0 before the decimal point.
Diffstat (limited to 'libqpdf/QPDF_Real.cc')
-rw-r--r--libqpdf/QPDF_Real.cc25
1 files changed, 24 insertions, 1 deletions
diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc
index b28c2f70..b4c8283f 100644
--- a/libqpdf/QPDF_Real.cc
+++ b/libqpdf/QPDF_Real.cc
@@ -25,7 +25,30 @@ QPDF_Real::unparse()
JSON
QPDF_Real::getJSON()
{
- return JSON::makeNumber(this->val);
+ // While PDF allows .x or -.x, JSON does not. Rather than
+ // convering 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";
+ }
+ 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);
+ }
+ else
+ {
+ result = this->val;
+ }
+ return JSON::makeNumber(result);
}
QPDFObject::object_type_e