summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_stream.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-23 23:52:53 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-23 23:52:53 +0000
commit367ed462b51799c008795b19e886ccbed221b9be (patch)
tree3c94f25900ec5617954dbfd3e615e6a4751ddfcd /core/fpdfapi/parser/cpdf_stream.cpp
parentc1dde5d9b3da2af6e6f81df09ed41ab9c34bbde4 (diff)
downloadpdfium-367ed462b51799c008795b19e886ccbed221b9be.tar.xz
Use pdfium::span<> in CPDF_Stream::SetData().
Conversion to span makes this more elegant in a number of places, owing to std::vector directly converting to span, and the bytestring's ToRawSpan(). Disambiguate single-argument forms to allow passing {} as an argument. Change-Id: Ibd5eaadca8d8cbbd589338f375c7ee8439fd3eb2 Reviewed-on: https://pdfium-review.googlesource.com/41272 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_stream.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_stream.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp
index 64478996a8..81d0e840c0 100644
--- a/core/fpdfapi/parser/cpdf_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -69,11 +69,10 @@ const CPDF_Stream* CPDF_Stream::AsStream() const {
return this;
}
-void CPDF_Stream::InitStream(const uint8_t* pData,
- uint32_t size,
+void CPDF_Stream::InitStream(pdfium::span<const uint8_t> pData,
std::unique_ptr<CPDF_Dictionary> pDict) {
m_pDict = std::move(pDict);
- SetData(pData, size);
+ SetData(pData);
}
void CPDF_Stream::InitStreamFromFile(
@@ -111,29 +110,31 @@ std::unique_ptr<CPDF_Object> CPDF_Stream::CloneNonCyclic(
std::move(pNewDict));
}
-void CPDF_Stream::SetDataAndRemoveFilter(const uint8_t* pData, uint32_t size) {
- SetData(pData, size);
+void CPDF_Stream::SetDataAndRemoveFilter(pdfium::span<const uint8_t> pData) {
+ SetData(pData);
m_pDict->RemoveFor("Filter");
m_pDict->RemoveFor(pdfium::stream::kDecodeParms);
}
-void CPDF_Stream::SetDataAndRemoveFilter(std::ostringstream* stream) {
+void CPDF_Stream::SetDataFromStringstreamAndRemoveFilter(
+ std::ostringstream* stream) {
if (stream->tellp() <= 0) {
- SetDataAndRemoveFilter(nullptr, 0);
+ SetDataAndRemoveFilter({});
return;
}
SetDataAndRemoveFilter(
- reinterpret_cast<const uint8_t*>(stream->str().c_str()), stream->tellp());
+ {reinterpret_cast<const uint8_t*>(stream->str().c_str()),
+ static_cast<size_t>(stream->tellp())});
}
-void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) {
+void CPDF_Stream::SetData(pdfium::span<const uint8_t> pData) {
std::unique_ptr<uint8_t, FxFreeDeleter> data_copy;
- if (pData) {
- data_copy.reset(FX_Alloc(uint8_t, size));
- memcpy(data_copy.get(), pData, size);
+ if (!pData.empty()) {
+ data_copy.reset(FX_Alloc(uint8_t, pData.size()));
+ memcpy(data_copy.get(), pData.data(), pData.size());
}
- SetData(std::move(data_copy), size);
+ SetData(std::move(data_copy), pData.size());
}
void CPDF_Stream::SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
@@ -147,14 +148,13 @@ void CPDF_Stream::SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size));
}
-void CPDF_Stream::SetData(std::ostringstream* stream) {
+void CPDF_Stream::SetDataFromStringstream(std::ostringstream* stream) {
if (stream->tellp() <= 0) {
- SetData(nullptr, 0);
+ SetData({});
return;
}
-
- SetData(reinterpret_cast<const uint8_t*>(stream->str().c_str()),
- stream->tellp());
+ SetData({reinterpret_cast<const uint8_t*>(stream->str().c_str()),
+ static_cast<size_t>(stream->tellp())});
}
bool CPDF_Stream::ReadRawData(FX_FILESIZE offset,