aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-06 23:37:25 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-07 14:26:31 +0200
commita3c99803954ad0f3762d986c953666c6517cad0c (patch)
treefeb0430418207377bfce817659040f3a869f057b
parentb361c5ce19a05ce8da60c767651521a9ce0210e5 (diff)
downloadqpdf-a3c99803954ad0f3762d986c953666c6517cad0c.tar.zst
Add next to Pl_String and fix comments
-rw-r--r--include/qpdf/Pl_String.hh18
-rw-r--r--libqpdf/JSON.cc2
-rw-r--r--libqpdf/Pl_String.cc10
-rw-r--r--qpdf/test_driver.cc2
4 files changed, 25 insertions, 7 deletions
diff --git a/include/qpdf/Pl_String.hh b/include/qpdf/Pl_String.hh
index a858257c..327598da 100644
--- a/include/qpdf/Pl_String.hh
+++ b/include/qpdf/Pl_String.hh
@@ -19,11 +19,23 @@
// continue to consider qpdf to be licensed under those terms. Please
// see the manual for additional information.
-// End-of-line pipeline that simply writes its data to a stdio FILE* object.
-
#ifndef PL_STRING_HH
#define PL_STRING_HH
+// This pipeline accumulates the data passed to it into a std::string,
+// a reference to which is passed in at construction. Each subsequent
+// use of this pipeline appends to the data accumulated so far.
+//
+// For this pipeline, "next" may be null. If a next pointer is
+// provided, this pipeline will also pass the data through to it and
+// will forward finish() to it.
+//
+// It is okay to not call finish() on this pipeline. This makes it
+// easy to stick this in front of another pipeline to capture data
+// that is written to the other pipeline without interfering with when
+// finish is called on the other pipeline and without having to put a
+// Pl_Concatenate after it.
+
#include <qpdf/Pipeline.hh>
#include <string>
@@ -32,7 +44,7 @@ class QPDF_DLL_CLASS Pl_String: public Pipeline
{
public:
QPDF_DLL
- Pl_String(char const* identifier, std::string& s);
+ Pl_String(char const* identifier, Pipeline* next, std::string& s);
QPDF_DLL
virtual ~Pl_String();
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc
index 8549b7ed..31675a42 100644
--- a/libqpdf/JSON.cc
+++ b/libqpdf/JSON.cc
@@ -200,7 +200,7 @@ std::string
JSON::unparse() const
{
std::string s;
- Pl_String p("unparse", s);
+ Pl_String p("unparse", nullptr, s);
write(&p, 0);
return s;
}
diff --git a/libqpdf/Pl_String.cc b/libqpdf/Pl_String.cc
index c9392821..d946a652 100644
--- a/libqpdf/Pl_String.cc
+++ b/libqpdf/Pl_String.cc
@@ -9,8 +9,8 @@ Pl_String::Members::Members(std::string& s) :
{
}
-Pl_String::Pl_String(char const* identifier, std::string& s) :
- Pipeline(identifier, 0),
+Pl_String::Pl_String(char const* identifier, Pipeline* next, std::string& s) :
+ Pipeline(identifier, next),
m(new Members(s))
{
}
@@ -25,9 +25,15 @@ void
Pl_String::write(unsigned char const* buf, size_t len)
{
this->m->s.append(reinterpret_cast<char const*>(buf), len);
+ if (getNext(true)) {
+ getNext()->write(buf, len);
+ }
}
void
Pl_String::finish()
{
+ if (getNext(true)) {
+ getNext()->finish();
+ }
}
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 79744162..849eb4a0 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -437,7 +437,7 @@ test_6(QPDF& pdf, char const* arg2)
throw std::logic_error("test 6 run on file with no metadata");
}
std::string buf;
- Pl_String bufpl("buffer", buf);
+ Pl_String bufpl("buffer", nullptr, buf);
metadata.pipeStreamData(&bufpl, 0, qpdf_dl_none);
bool cleartext = false;
if (buf.substr(0, 9) == "<?xpacket") {