summaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFAcroFormDocumentHelper.cc
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-01-05 13:56:34 +0100
committerm-holger <m-holger@kubitscheck.org>2023-05-19 17:58:14 +0200
commite7e24fe0706f40b76058bb4b2b46c0307cb6255d (patch)
tree395669e5cba240dcd2d5f54a16e5da9969f8d02e /libqpdf/QPDFAcroFormDocumentHelper.cc
parent55abecc42dc44d1b93337afe9628fea029a85696 (diff)
downloadqpdf-e7e24fe0706f40b76058bb4b2b46c0307cb6255d.tar.zst
Tidy QPDFAcroFormDocumentHelper::addAndRenameFormFields
Diffstat (limited to 'libqpdf/QPDFAcroFormDocumentHelper.cc')
-rw-r--r--libqpdf/QPDFAcroFormDocumentHelper.cc83
1 files changed, 39 insertions, 44 deletions
diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc
index 70e1b9c9..8c2c5e56 100644
--- a/libqpdf/QPDFAcroFormDocumentHelper.cc
+++ b/libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -68,53 +68,48 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields(
{
analyze();
std::map<std::string, std::string> renames;
- std::list<QPDFObjectHandle> queue;
- queue.insert(queue.begin(), fields.begin(), fields.end());
- std::set<QPDFObjGen> seen;
- while (!queue.empty()) {
- QPDFObjectHandle obj = queue.front();
- queue.pop_front();
- auto og = obj.getObjGen();
- if (seen.count(og)) {
- // loop
- continue;
- }
- seen.insert(og);
- auto kids = obj.getKey("/Kids");
- if (kids.isArray()) {
- for (auto kid: kids.aitems()) {
- queue.push_back(kid);
+ QPDFObjGen::set seen;
+ for (std::list<QPDFObjectHandle> queue{fields.begin(), fields.end()};
+ !queue.empty();
+ queue.pop_front()) {
+ auto& obj = queue.front();
+ if (seen.add(obj)) {
+ auto kids = obj.getKey("/Kids");
+ if (kids.isArray()) {
+ for (auto kid: kids.aitems()) {
+ queue.push_back(kid);
+ }
}
- }
- if (obj.hasKey("/T")) {
- // Find something we can append to the partial name that
- // makes the fully qualified name unique. When we find
- // something, reuse the same suffix for all fields in this
- // group with the same name. We can only change the name
- // of fields that have /T, and this field's /T is always
- // at the end of the fully qualified name, appending to /T
- // has the effect of appending the same thing to the fully
- // qualified name.
- std::string old_name =
- QPDFFormFieldObjectHelper(obj).getFullyQualifiedName();
- if (renames.count(old_name) == 0) {
- std::string new_name = old_name;
- int suffix = 0;
- std::string append;
- while (!getFieldsWithQualifiedName(new_name).empty()) {
- ++suffix;
- append = "+" + std::to_string(suffix);
- new_name = old_name + append;
+ if (obj.hasKey("/T")) {
+ // Find something we can append to the partial name that
+ // makes the fully qualified name unique. When we find
+ // something, reuse the same suffix for all fields in this
+ // group with the same name. We can only change the name
+ // of fields that have /T, and this field's /T is always
+ // at the end of the fully qualified name, appending to /T
+ // has the effect of appending the same thing to the fully
+ // qualified name.
+ std::string old_name =
+ QPDFFormFieldObjectHelper(obj).getFullyQualifiedName();
+ if (renames.count(old_name) == 0) {
+ std::string new_name = old_name;
+ int suffix = 0;
+ std::string append;
+ while (!getFieldsWithQualifiedName(new_name).empty()) {
+ ++suffix;
+ append = "+" + std::to_string(suffix);
+ new_name = old_name + append;
+ }
+ renames[old_name] = append;
+ }
+ std::string append = renames[old_name];
+ if (!append.empty()) {
+ obj.replaceKey(
+ "/T",
+ QPDFObjectHandle::newUnicodeString(
+ obj.getKey("/T").getUTF8Value() + append));
}
- renames[old_name] = append;
- }
- std::string append = renames[old_name];
- if (!append.empty()) {
- obj.replaceKey(
- "/T",
- QPDFObjectHandle::newUnicodeString(
- obj.getKey("/T").getUTF8Value() + append));
}
}
}