summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-17 16:41:28 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-17 16:41:28 +0000
commitb7973bb5a0ad2f83a71362d601a928964559004a (patch)
tree74acc13d4e542b668f727c323a1ccc97461ec55f /core/fpdfapi/parser
parent8cfcb7da37352b22517892e6eabcedb77676cdf7 (diff)
downloadpdfium-b7973bb5a0ad2f83a71362d601a928964559004a.tar.xz
Reland "Return pdfium::span<wchar_t> from WideString::GetBuffer().""
This reverts commit 0d32b8fda53e02c1036d39f7290d4f59f2b58ca4. Restore behaviour on trunk. TBR: dsinclair@chromium.org Change-Id: Ia867f09ae9d2885595c4d9b300a058431dfd84f2 Reviewed-on: https://pdfium-review.googlesource.com/30811 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index d7114b66c5..90dca2edcb 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -425,6 +425,7 @@ bool PDF_DataDecode(const uint8_t* src_buf,
}
WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) {
+ int dest_pos = 0;
WideString result;
if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) ||
(src_data[0] == 0xff && src_data[1] == 0xfe))) {
@@ -432,17 +433,15 @@ WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) {
if (!max_chars)
return result;
+ pdfium::span<wchar_t> dest_buf = result.GetBuffer(max_chars);
bool bBE = src_data[0] == 0xfe || (src_data[0] == 0xff && !src_data[2]);
- wchar_t* dest_buf = result.GetBuffer(max_chars);
const uint8_t* uni_str = src_data + 2;
- int dest_pos = 0;
for (uint32_t i = 0; i < max_chars * 2; i += 2) {
uint16_t unicode = GetUnicodeFromBytes(uni_str + i, bBE);
if (unicode != 0x1b) {
dest_buf[dest_pos++] = unicode;
continue;
}
-
i += 2;
while (i < max_chars * 2) {
uint16_t unicode2 = GetUnicodeFromBytes(uni_str + i, bBE);
@@ -451,13 +450,13 @@ WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) {
break;
}
}
- result.ReleaseBuffer(dest_pos);
} else {
- wchar_t* dest_buf = result.GetBuffer(src_len);
+ pdfium::span<wchar_t> dest_buf = result.GetBuffer(src_len);
for (uint32_t i = 0; i < src_len; ++i)
dest_buf[i] = PDFDocEncoding[src_data[i]];
- result.ReleaseBuffer(src_len);
+ dest_pos = src_len;
}
+ result.ReleaseBuffer(dest_pos);
return result;
}