aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-06-20 19:04:57 +0200
committerJay Berkenbilt <ejb@ql.org>2019-06-21 19:17:21 +0200
commit3608afd5c528b7a9d95d227cb6c4f33d303fcfcd (patch)
tree9f1a59273a85f877e142e3403d68bb0a303029d2 /libqpdf
parent42306e2ff8716ce9a8f57da791122cc88308890c (diff)
downloadqpdf-3608afd5c528b7a9d95d227cb6c4f33d303fcfcd.tar.zst
Add new integer accessors to QPDFObjectHandle
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFObjectHandle.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 2cffb166..b3f7daec 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -26,6 +26,7 @@
#include <stdexcept>
#include <stdlib.h>
#include <ctype.h>
+#include <limits.h>
class TerminateParsing
{
@@ -406,6 +407,82 @@ QPDFObjectHandle::getIntValue()
}
}
+int
+QPDFObjectHandle::getIntValueAsInt()
+{
+ int result = 0;
+ long long v = getIntValue();
+ if (v < INT_MIN)
+ {
+ QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MIN");
+ warnIfPossible(
+ "requested value of integer is too small; returning INT_MIN",
+ false);
+ result = INT_MIN;
+ }
+ else if (v > INT_MAX)
+ {
+ QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MAX");
+ warnIfPossible(
+ "requested value of integer is too big; returning INT_MAX",
+ false);
+ result = INT_MAX;
+ }
+ else
+ {
+ result = static_cast<int>(v);
+ }
+ return result;
+}
+
+unsigned long long
+QPDFObjectHandle::getUIntValue()
+{
+ unsigned long long result = 0;
+ long long v = getIntValue();
+ if (v < 0)
+ {
+ QTC::TC("qpdf", "QPDFObjectHandle uint returning 0");
+ warnIfPossible(
+ "unsigned value request for negative number; returning 0",
+ false);
+ }
+ else
+ {
+ result = static_cast<unsigned long long>(v);
+ }
+ return result;
+}
+
+unsigned int
+QPDFObjectHandle::getUIntValueAsUInt()
+{
+ unsigned int result = 0;
+ long long v = getIntValue();
+ if (v < 0)
+ {
+ QTC::TC("qpdf", "QPDFObjectHandle uint uint returning 0");
+ warnIfPossible(
+ "unsigned integer value request for negative number; returning 0",
+ false);
+ result = 0;
+ }
+ else if (v > UINT_MAX)
+ {
+ QTC::TC("qpdf", "QPDFObjectHandle uint returning UINT_MAX");
+ warnIfPossible(
+ "requested value of unsigned integer is too big;"
+ " returning UINT_MAX",
+ false);
+ result = UINT_MAX;
+ }
+ else
+ {
+ result = static_cast<unsigned int>(v);
+ }
+ return result;
+}
+
// Real accessors
std::string