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