diff options
author | m-holger <m-holger@kubitscheck.org> | 2023-01-01 13:47:03 +0100 |
---|---|---|
committer | m-holger <m-holger@kubitscheck.org> | 2023-04-01 14:56:29 +0200 |
commit | 182c2480df3d2dee3e430e02afe6bbee3e45eadd (patch) | |
tree | 6c5c834617b09c1bf8628ae340068b5a96ad91b0 /libqpdf/QPDF_Array.cc | |
parent | 4d37389befc705b671d8fa7a1da2b7117b50f454 (diff) | |
download | qpdf-182c2480df3d2dee3e430e02afe6bbee3e45eadd.tar.zst |
Refactor QPDF_Array::setItem and rename to setAt
Diffstat (limited to 'libqpdf/QPDF_Array.cc')
-rw-r--r-- | libqpdf/QPDF_Array.cc | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index e4e1668e..d7505468 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -1,9 +1,6 @@ #include <qpdf/QPDF_Array.hh> -#include <qpdf/QIntC.hh> #include <qpdf/QPDFObject_private.hh> -#include <qpdf/QUtil.hh> -#include <stdexcept> static const QPDFObjectHandle null_oh = QPDFObjectHandle::newNull(); @@ -188,18 +185,19 @@ QPDF_Array::getAsVector(std::vector<QPDFObjectHandle>& v) const } } -void -QPDF_Array::setItem(int n, QPDFObjectHandle const& oh) +bool +QPDF_Array::setAt(int at, QPDFObjectHandle const& oh) { + if (at < 0 || at >= size()) { + return false; + } + checkOwnership(oh); if (sparse) { - sp_elements.setAt(n, oh); + sp_elements.setAt(at, oh); } else { - size_t idx = size_t(n); - if (n < 0 || idx >= elements.size()) { - throw std::logic_error("bounds error setting item in QPDF_Array"); - } - elements[idx] = oh.getObj(); + elements[size_t(at)] = oh.getObj(); } + return true; } void |