mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Add new method Pl_Buffer::getString
This commit is contained in:
parent
d11622b6fd
commit
3237ef70fb
@ -64,6 +64,10 @@ class QPDF_DLL_CLASS Pl_Buffer: public Pipeline
|
||||
QPDF_DLL
|
||||
void getMallocBuffer(unsigned char** buf, size_t* len);
|
||||
|
||||
// Same as getBuffer but returns the result as a string.
|
||||
QPDF_DLL
|
||||
std::string getString();
|
||||
|
||||
private:
|
||||
class QPDF_DLL_PRIVATE Members
|
||||
{
|
||||
|
@ -53,6 +53,17 @@ Pl_Buffer::getBuffer()
|
||||
return b;
|
||||
}
|
||||
|
||||
std::string
|
||||
Pl_Buffer::getString()
|
||||
{
|
||||
if (!m->ready) {
|
||||
throw std::logic_error("Pl_Buffer::getString() called when not ready");
|
||||
}
|
||||
auto s = std::move(m->data);
|
||||
m->data.clear();
|
||||
return s;
|
||||
}
|
||||
|
||||
std::shared_ptr<Buffer>
|
||||
Pl_Buffer::getBufferSharedPointer()
|
||||
{
|
||||
|
@ -584,8 +584,7 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances(
|
||||
ResourceReplacer rr(dr_map, rf.getNamesByResourceType());
|
||||
Pl_Buffer buf_pl("filtered DA");
|
||||
da_stream.filterAsContents(&rr, &buf_pl);
|
||||
auto buf = buf_pl.getBufferSharedPointer();
|
||||
std::string new_da(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
|
||||
std::string new_da = buf_pl.getString();
|
||||
obj.replaceKey("/DA", QPDFObjectHandle::newString(new_da));
|
||||
}
|
||||
|
||||
|
@ -1708,8 +1708,7 @@ QPDFObjectHandle::pipeContentStreams(
|
||||
need_newline = (lc.getLastChar() != static_cast<unsigned char>('\n'));
|
||||
QTC::TC("qpdf", "QPDFObjectHandle need_newline", need_newline ? 0 : 1);
|
||||
}
|
||||
std::unique_ptr<Buffer> b(buf.getBuffer());
|
||||
p->write(b->getBuffer(), b->getSize());
|
||||
p->writeString(buf.getString());
|
||||
p->finish();
|
||||
}
|
||||
|
||||
|
@ -1579,10 +1579,7 @@ QPDFWriter::unparseObject(
|
||||
m->cur_data_key.length());
|
||||
pl.writeString(val);
|
||||
pl.finish();
|
||||
auto buf = bufpl.getBufferSharedPointer();
|
||||
val = QPDF_String(
|
||||
std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()))
|
||||
.unparse(true);
|
||||
val = QPDF_String(bufpl.getString()).unparse(true);
|
||||
} else {
|
||||
auto tmp_ph = QUtil::make_unique_cstr(val);
|
||||
char* tmp = tmp_ph.get();
|
||||
|
@ -229,13 +229,11 @@ process_with_aes(
|
||||
aes.writeString(data);
|
||||
}
|
||||
aes.finish();
|
||||
auto bufp = buffer.getBufferSharedPointer();
|
||||
if (outlength == 0) {
|
||||
outlength = bufp->getSize();
|
||||
return buffer.getString();
|
||||
} else {
|
||||
outlength = std::min(outlength, bufp->getSize());
|
||||
return buffer.getString().substr(0, outlength);
|
||||
}
|
||||
return {reinterpret_cast<char*>(bufp->getBuffer()), outlength};
|
||||
}
|
||||
|
||||
static std::string
|
||||
@ -1021,8 +1019,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og)
|
||||
key.length());
|
||||
pl.writeString(str);
|
||||
pl.finish();
|
||||
auto buf = bufpl.getBufferSharedPointer();
|
||||
str = std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
|
||||
str = bufpl.getString();
|
||||
} else {
|
||||
QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
|
||||
size_t vlen = str.length();
|
||||
|
Loading…
Reference in New Issue
Block a user