2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Code tidy - Clang-Tidy rule modernize-return-braced-init-list

This commit is contained in:
m-holger 2023-05-27 21:04:32 +01:00
parent acd0acf169
commit 320bbb9854
14 changed files with 67 additions and 69 deletions

View File

@ -81,7 +81,7 @@ class QPDFOutlineObjectHelper: public QPDFObjectHelper
static QPDFOutlineObjectHelper
create(QPDFObjectHandle oh, QPDFOutlineDocumentHelper& dh, int depth)
{
return QPDFOutlineObjectHelper(oh, dh, depth);
return {oh, dh, depth};
}
};

View File

@ -37,7 +37,7 @@ InputSource::readLine(size_t max_line_length)
if (line_length < max_line_length) {
buf[line_length] = '\0';
}
return std::string(buf);
return {buf};
}
bool

View File

@ -269,7 +269,7 @@ JSON::encode_string(std::string const& str)
JSON
JSON::makeDictionary()
{
return JSON(std::make_unique<JSON_dictionary>());
return {std::make_unique<JSON_dictionary>()};
}
JSON
@ -299,7 +299,7 @@ JSON::checkDictionaryKeySeen(std::string const& key)
JSON
JSON::makeArray()
{
return JSON(std::make_unique<JSON_array>());
return {std::make_unique<JSON_array>()};
}
JSON
@ -320,43 +320,43 @@ JSON::addArrayElement(JSON const& val)
JSON
JSON::makeString(std::string const& utf8)
{
return JSON(std::make_unique<JSON_string>(utf8));
return {std::make_unique<JSON_string>(utf8)};
}
JSON
JSON::makeInt(long long int value)
{
return JSON(std::make_unique<JSON_number>(value));
return {std::make_unique<JSON_number>(value)};
}
JSON
JSON::makeReal(double value)
{
return JSON(std::make_unique<JSON_number>(value));
return {std::make_unique<JSON_number>(value)};
}
JSON
JSON::makeNumber(std::string const& encoded)
{
return JSON(std::make_unique<JSON_number>(encoded));
return {std::make_unique<JSON_number>(encoded)};
}
JSON
JSON::makeBool(bool value)
{
return JSON(std::make_unique<JSON_bool>(value));
return {std::make_unique<JSON_bool>(value)};
}
JSON
JSON::makeNull()
{
return JSON(std::make_unique<JSON_null>());
return {std::make_unique<JSON_null>()};
}
JSON
JSON::makeBlob(std::function<void(Pipeline*)> fn)
{
return JSON(std::make_unique<JSON_blob>(fn));
return {std::make_unique<JSON_blob>(fn)};
}
bool

View File

@ -689,7 +689,7 @@ NNTreeImpl::begin()
NNTreeImpl::iterator
NNTreeImpl::end()
{
return iterator(*this);
return {*this};
}
NNTreeImpl::iterator

View File

@ -2212,7 +2212,7 @@ QPDF::getVersionAsPDFVersion()
minor = QUtil::string_to_int(match[2].str().c_str());
}
return PDFVersion(major, minor, extension_level);
return {major, minor, extension_level};
}
std::string
@ -2483,7 +2483,7 @@ QPDF::damagedPDF(
qpdf_offset_t offset,
std::string const& message)
{
return QPDFExc(qpdf_e_damaged_pdf, input->getName(), object, offset, message);
return {qpdf_e_damaged_pdf, input->getName(), object, offset, message};
}
// Return an exception of type qpdf_e_damaged_pdf. The object is taken from
@ -2499,7 +2499,7 @@ QPDF::damagedPDF(
QPDFExc
QPDF::damagedPDF(std::string const& object, qpdf_offset_t offset, std::string const& message)
{
return QPDFExc(qpdf_e_damaged_pdf, m->file->getName(), object, offset, message);
return {qpdf_e_damaged_pdf, m->file->getName(), object, offset, message};
}
// Return an exception of type qpdf_e_damaged_pdf. The filename is taken from m->file and the

View File

@ -194,7 +194,7 @@ QPDFCrypto_openssl::MD5_digest(MD5_Digest d)
std::string
QPDFCrypto_openssl::SHA2_digest()
{
return std::string(reinterpret_cast<char*>(md_out), sha2_bits / 8);
return {reinterpret_cast<char*>(md_out), sha2_bits / 8};
}
void

View File

@ -428,7 +428,7 @@ QPDFJob::parseNumrange(char const* range, int max)
} catch (std::runtime_error& e) {
usage(e.what());
}
return std::vector<int>();
return {};
}
std::unique_ptr<QPDF>

View File

@ -57,7 +57,7 @@ QPDFMatrix::unparse() const
QPDFObjectHandle::Matrix
QPDFMatrix::getAsMatrix() const
{
return QPDFObjectHandle::Matrix(a, b, c, d, e, f);
return {a, b, c, d, e, f};
}
void
@ -124,11 +124,11 @@ QPDFMatrix::transformRectangle(QPDFObjectHandle::Rectangle r) const
transform(r.llx, r.ury, tx.at(1), ty.at(1));
transform(r.urx, r.lly, tx.at(2), ty.at(2));
transform(r.urx, r.ury, tx.at(3), ty.at(3));
return QPDFObjectHandle::Rectangle(
return {
*std::min_element(tx.begin(), tx.end()),
*std::min_element(ty.begin(), ty.end()),
*std::max_element(tx.begin(), tx.end()),
*std::max_element(ty.begin(), ty.end()));
*std::max_element(ty.begin(), ty.end())};
}
bool

View File

@ -54,8 +54,7 @@ QPDFNameTreeObjectHelper::QPDFNameTreeObjectHelper(QPDFObjectHandle oh, QPDF& q,
QPDFNameTreeObjectHelper
QPDFNameTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair)
{
return QPDFNameTreeObjectHelper(
qpdf.makeIndirectObject("<< /Names [] >>"_qpdf), qpdf, auto_repair);
return {qpdf.makeIndirectObject("<< /Names [] >>"_qpdf), qpdf, auto_repair};
}
QPDFNameTreeObjectHelper::iterator::iterator(std::shared_ptr<NNTreeIterator> const& i) :
@ -135,33 +134,33 @@ QPDFNameTreeObjectHelper::iterator::remove()
QPDFNameTreeObjectHelper::iterator
QPDFNameTreeObjectHelper::begin() const
{
return iterator(std::make_shared<NNTreeIterator>(m->impl->begin()));
return {std::make_shared<NNTreeIterator>(m->impl->begin())};
}
QPDFNameTreeObjectHelper::iterator
QPDFNameTreeObjectHelper::end() const
{
return iterator(std::make_shared<NNTreeIterator>(m->impl->end()));
return {std::make_shared<NNTreeIterator>(m->impl->end())};
}
QPDFNameTreeObjectHelper::iterator
QPDFNameTreeObjectHelper::last() const
{
return iterator(std::make_shared<NNTreeIterator>(m->impl->last()));
return {std::make_shared<NNTreeIterator>(m->impl->last())};
}
QPDFNameTreeObjectHelper::iterator
QPDFNameTreeObjectHelper::find(std::string const& key, bool return_prev_if_not_found)
{
auto i = m->impl->find(QPDFObjectHandle::newUnicodeString(key), return_prev_if_not_found);
return iterator(std::make_shared<NNTreeIterator>(i));
return {std::make_shared<NNTreeIterator>(i)};
}
QPDFNameTreeObjectHelper::iterator
QPDFNameTreeObjectHelper::insert(std::string const& key, QPDFObjectHandle value)
{
auto i = m->impl->insert(QPDFObjectHandle::newUnicodeString(key), value);
return iterator(std::make_shared<NNTreeIterator>(i));
return {std::make_shared<NNTreeIterator>(i)};
}
bool

View File

@ -56,8 +56,7 @@ QPDFNumberTreeObjectHelper::QPDFNumberTreeObjectHelper(
QPDFNumberTreeObjectHelper
QPDFNumberTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair)
{
return QPDFNumberTreeObjectHelper(
qpdf.makeIndirectObject("<< /Nums [] >>"_qpdf), qpdf, auto_repair);
return {qpdf.makeIndirectObject("<< /Nums [] >>"_qpdf), qpdf, auto_repair};
}
QPDFNumberTreeObjectHelper::iterator::iterator(std::shared_ptr<NNTreeIterator> const& i) :
@ -137,33 +136,33 @@ QPDFNumberTreeObjectHelper::iterator::remove()
QPDFNumberTreeObjectHelper::iterator
QPDFNumberTreeObjectHelper::begin() const
{
return iterator(std::make_shared<NNTreeIterator>(m->impl->begin()));
return {std::make_shared<NNTreeIterator>(m->impl->begin())};
}
QPDFNumberTreeObjectHelper::iterator
QPDFNumberTreeObjectHelper::end() const
{
return iterator(std::make_shared<NNTreeIterator>(m->impl->end()));
return {std::make_shared<NNTreeIterator>(m->impl->end())};
}
QPDFNumberTreeObjectHelper::iterator
QPDFNumberTreeObjectHelper::last() const
{
return iterator(std::make_shared<NNTreeIterator>(m->impl->last()));
return {std::make_shared<NNTreeIterator>(m->impl->last())};
}
QPDFNumberTreeObjectHelper::iterator
QPDFNumberTreeObjectHelper::find(numtree_number key, bool return_prev_if_not_found)
{
auto i = m->impl->find(QPDFObjectHandle::newInteger(key), return_prev_if_not_found);
return iterator(std::make_shared<NNTreeIterator>(i));
return {std::make_shared<NNTreeIterator>(i)};
}
QPDFNumberTreeObjectHelper::iterator
QPDFNumberTreeObjectHelper::insert(numtree_number key, QPDFObjectHandle value)
{
auto i = m->impl->insert(QPDFObjectHandle::newInteger(key), value);
return iterator(std::make_shared<NNTreeIterator>(i));
return {std::make_shared<NNTreeIterator>(i)};
}
bool

View File

@ -752,7 +752,7 @@ QPDFObjectHandle::getValueAsInlineImage(std::string& value)
QPDFObjectHandle::QPDFArrayItems
QPDFObjectHandle::aitems()
{
return QPDFArrayItems(*this);
return *this;
}
int
@ -826,11 +826,11 @@ QPDFObjectHandle::getArrayAsRectangle()
return {};
}
}
return Rectangle(
return {
std::min(items[0], items[2]),
std::min(items[1], items[3]),
std::max(items[0], items[2]),
std::max(items[1], items[3]));
std::max(items[1], items[3])};
}
return {};
}
@ -848,7 +848,7 @@ QPDFObjectHandle::getArrayAsMatrix()
return {};
}
}
return Matrix(items[0], items[1], items[2], items[3], items[4], items[5]);
return {items[0], items[1], items[2], items[3], items[4], items[5]};
}
return {};
}
@ -959,7 +959,7 @@ QPDFObjectHandle::eraseItemAndGetOld(int at)
QPDFObjectHandle::QPDFDictItems
QPDFObjectHandle::ditems()
{
return QPDFDictItems(*this);
return {*this};
}
bool
@ -1862,61 +1862,61 @@ QPDFObjectHandle::getParsedOffset()
QPDFObjectHandle
QPDFObjectHandle::newBool(bool value)
{
return QPDFObjectHandle(QPDF_Bool::create(value));
return {QPDF_Bool::create(value)};
}
QPDFObjectHandle
QPDFObjectHandle::newNull()
{
return QPDFObjectHandle(QPDF_Null::create());
return {QPDF_Null::create()};
}
QPDFObjectHandle
QPDFObjectHandle::newInteger(long long value)
{
return QPDFObjectHandle(QPDF_Integer::create(value));
return {QPDF_Integer::create(value)};
}
QPDFObjectHandle
QPDFObjectHandle::newReal(std::string const& value)
{
return QPDFObjectHandle(QPDF_Real::create(value));
return {QPDF_Real::create(value)};
}
QPDFObjectHandle
QPDFObjectHandle::newReal(double value, int decimal_places, bool trim_trailing_zeroes)
{
return QPDFObjectHandle(QPDF_Real::create(value, decimal_places, trim_trailing_zeroes));
return {QPDF_Real::create(value, decimal_places, trim_trailing_zeroes)};
}
QPDFObjectHandle
QPDFObjectHandle::newName(std::string const& name)
{
return QPDFObjectHandle(QPDF_Name::create(name));
return {QPDF_Name::create(name)};
}
QPDFObjectHandle
QPDFObjectHandle::newString(std::string const& str)
{
return QPDFObjectHandle(QPDF_String::create(str));
return {QPDF_String::create(str)};
}
QPDFObjectHandle
QPDFObjectHandle::newUnicodeString(std::string const& utf8_str)
{
return QPDFObjectHandle(QPDF_String::create_utf16(utf8_str));
return {QPDF_String::create_utf16(utf8_str)};
}
QPDFObjectHandle
QPDFObjectHandle::newOperator(std::string const& value)
{
return QPDFObjectHandle(QPDF_Operator::create(value));
return {QPDF_Operator::create(value)};
}
QPDFObjectHandle
QPDFObjectHandle::newInlineImage(std::string const& value)
{
return QPDFObjectHandle(QPDF_InlineImage::create(value));
return {QPDF_InlineImage::create(value)};
}
QPDFObjectHandle
@ -1928,7 +1928,7 @@ QPDFObjectHandle::newArray()
QPDFObjectHandle
QPDFObjectHandle::newArray(std::vector<QPDFObjectHandle> const& items)
{
return QPDFObjectHandle(QPDF_Array::create(items));
return {QPDF_Array::create(items)};
}
QPDFObjectHandle
@ -1995,7 +1995,7 @@ QPDFObjectHandle::newDictionary()
QPDFObjectHandle
QPDFObjectHandle::newDictionary(std::map<std::string, QPDFObjectHandle> const& items)
{
return QPDFObjectHandle(QPDF_Dictionary::create(items));
return {QPDF_Dictionary::create(items)};
}
QPDFObjectHandle
@ -2060,7 +2060,7 @@ QPDFObjectHandle::shallowCopy()
if (!dereference()) {
throw std::logic_error("operation attempted on uninitialized QPDFObjectHandle");
}
return QPDFObjectHandle(obj->copy());
return {obj->copy()};
}
QPDFObjectHandle
@ -2069,7 +2069,7 @@ QPDFObjectHandle::unsafeShallowCopy()
if (!dereference()) {
throw std::logic_error("operation attempted on uninitialized QPDFObjectHandle");
}
return QPDFObjectHandle(obj->copy(true));
return {obj->copy(true)};
}
void
@ -2471,13 +2471,13 @@ QPDFObjectHandle::QPDFDictItems::iterator::Members::Members(QPDFObjectHandle& oh
QPDFObjectHandle::QPDFDictItems::iterator
QPDFObjectHandle::QPDFDictItems::begin()
{
return iterator(oh, true);
return {oh, true};
}
QPDFObjectHandle::QPDFDictItems::iterator
QPDFObjectHandle::QPDFDictItems::end()
{
return iterator(oh, false);
return {oh, false};
}
QPDFObjectHandle::QPDFArrayItems::QPDFArrayItems(QPDFObjectHandle const& oh) :
@ -2551,13 +2551,13 @@ QPDFObjectHandle::QPDFArrayItems::iterator::Members::Members(QPDFObjectHandle& o
QPDFObjectHandle::QPDFArrayItems::iterator
QPDFObjectHandle::QPDFArrayItems::begin()
{
return iterator(oh, true);
return {oh, true};
}
QPDFObjectHandle::QPDFArrayItems::iterator
QPDFObjectHandle::QPDFArrayItems::end()
{
return iterator(oh, false);
return {oh, false};
}
QPDFObjGen

View File

@ -662,7 +662,7 @@ QPDFPageObjectHelper::shallowCopyPage()
QPDF& qpdf =
this->oh.getQPDF("QPDFPageObjectHelper::shallowCopyPage called with a direct object");
QPDFObjectHandle new_page = this->oh.shallowCopy();
return QPDFPageObjectHelper(qpdf.makeIndirectObject(new_page));
return {qpdf.makeIndirectObject(new_page)};
}
QPDFObjectHandle::Matrix
@ -758,7 +758,7 @@ QPDFPageObjectHelper::getMatrixForFormXObjectPlacement(
QPDFObjectHandle fdict = fo.getDict();
QPDFObjectHandle bbox_obj = fdict.getKey("/BBox");
if (!bbox_obj.isRectangle()) {
return QPDFMatrix();
return {};
}
QPDFMatrix wmatrix; // work matrix
@ -793,7 +793,7 @@ QPDFPageObjectHelper::getMatrixForFormXObjectPlacement(
// Calculate a scale factor, if needed. Shrink or expand if needed and allowed.
if ((T.urx == T.llx) || (T.ury == T.lly)) {
// avoid division by zero
return QPDFMatrix();
return {};
}
double rect_w = rect.urx - rect.llx;
double rect_h = rect.ury - rect.lly;

View File

@ -164,7 +164,7 @@ pad_or_truncate_password_V4(std::string const& password)
{
char k1[key_bytes];
pad_or_truncate_password_V4(password, k1);
return std::string(k1, key_bytes);
return {k1, key_bytes};
}
static std::string
@ -235,7 +235,7 @@ process_with_aes(
} else {
outlength = std::min(outlength, bufp->getSize());
}
return std::string(reinterpret_cast<char*>(bufp->getBuffer()), outlength);
return {reinterpret_cast<char*>(bufp->getBuffer()), outlength};
}
static std::string
@ -355,7 +355,7 @@ QPDF::compute_data_key(
md5.encodeDataIncrementally(result.c_str(), result.length());
MD5::Digest digest;
md5.digest(digest);
return std::string(reinterpret_cast<char*>(digest), std::min(result.length(), toS(16)));
return {reinterpret_cast<char*>(digest), std::min(result.length(), toS(16))};
}
std::string
@ -401,7 +401,7 @@ QPDF::compute_encryption_key_from_password(std::string const& password, Encrypti
MD5::Digest digest;
int key_len = std::min(toI(sizeof(digest)), data.getLengthBytes());
iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0), key_len);
return std::string(reinterpret_cast<char*>(digest), toS(key_len));
return {reinterpret_cast<char*>(digest), toS(key_len)};
}
static void
@ -448,7 +448,7 @@ compute_O_value(
data.getLengthBytes(),
(data.getR() >= 3) ? 20 : 1,
false);
return std::string(upass, key_bytes);
return {upass, key_bytes};
}
static std::string
@ -467,7 +467,7 @@ compute_U_value_R2(std::string const& user_password, QPDF::EncryptionData const&
data.getLengthBytes(),
1,
false);
return std::string(udata, key_bytes);
return {udata, key_bytes};
}
static std::string
@ -496,7 +496,7 @@ compute_U_value_R3(std::string const& user_password, QPDF::EncryptionData const&
for (unsigned int i = sizeof(MD5::Digest); i < key_bytes; ++i) {
result[i] = static_cast<char>((i * i) % 0xff);
}
return std::string(result, key_bytes);
return {result, key_bytes};
}
static std::string

View File

@ -903,14 +903,14 @@ QUtil::get_current_qpdf_time()
// Don't know how to get timezone on this platform
int tzoff = 0;
# endif
return QPDFTime(
return {
static_cast<int>(ltime.tm_year + 1900),
static_cast<int>(ltime.tm_mon + 1),
static_cast<int>(ltime.tm_mday),
static_cast<int>(ltime.tm_hour),
static_cast<int>(ltime.tm_min),
static_cast<int>(ltime.tm_sec),
tzoff);
tzoff};
#endif
}