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

Add QPDFObjectHandle::parse for strings with context

This commit is contained in:
Jay Berkenbilt 2021-02-15 11:32:56 -05:00
parent 7eb903d9aa
commit a773f4c71d
5 changed files with 40 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2021-02-15 Jay Berkenbilt <ejb@ql.org>
* Add a version of QPDFObjectHandle::parse that takes a QPDF* as
context so that it can parse strings containing indirect object
references.
2021-02-14 Jay Berkenbilt <ejb@ql.org>
* Add new versions of QPDFObjectHandle::replaceStreamData that

View File

@ -379,6 +379,20 @@ class QPDFObjectHandle
static QPDFObjectHandle parse(std::string const& object_str,
std::string const& object_description = "");
// Construct an object of any type from a string representation of
// the object. Indirect object syntax (obj gen R) is allowed and
// will create indirect references within the passed-in context.
// If object_description is provided, it will appear in the
// message of any QPDFExc exception thrown for invalid syntax.
// Note that you can't parse an indirect object reference all by
// itself as parse will stop at the end of the first complete
// object, which will just be the first number and will report
// that there is trailing data at the end of the string.
QPDF_DLL
static QPDFObjectHandle parse(QPDF* context,
std::string const& object_str,
std::string const& object_description = "");
// Construct an object as above by reading from the given
// InputSource at its current position and using the tokenizer you
// supply. Indirect objects and encrypted strings are permitted.

View File

@ -1692,13 +1692,21 @@ QPDFObjectHandle::wrapInArray()
QPDFObjectHandle
QPDFObjectHandle::parse(std::string const& object_str,
std::string const& object_description)
{
return parse(nullptr, object_str, object_description);
}
QPDFObjectHandle
QPDFObjectHandle::parse(QPDF* context,
std::string const& object_str,
std::string const& object_description)
{
PointerHolder<InputSource> input =
new BufferInputSource("parsed object", object_str);
QPDFTokenizer tokenizer;
bool empty = false;
QPDFObjectHandle result =
parse(input, object_description, tokenizer, empty, 0, 0);
parse(input, object_description, tokenizer, empty, 0, context);
size_t offset = QIntC::to_size(input->tell());
while (offset < object_str.length())
{

View File

@ -5194,6 +5194,14 @@ print "\n";
<classname>QPDFObjectHandle</classname> object.
</para>
</listitem>
<listitem>
<para>
Add a version of
<function>QPDFObjectHandle::parse</function> that takes a
<classname>QPDF</classname> pointer as context so that it
can parse strings containing indirect object references.
</para>
</listitem>
<listitem>
<para>
Re-implement <classname>QPDFNameTreeObjectHelper</classname>

View File

@ -1319,6 +1319,9 @@ void runtest(int n, char const* filename1, char const* arg2)
std::cout << "trailing data: " << e.what()
<< std::endl;
}
assert(QPDFObjectHandle::parse(
&pdf, "[1 0 R]", "indirect test").unparse() ==
"[ 1 0 R ]");
}
else if (n == 32)
{