summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/fpdf_parser_utility.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser/fpdf_parser_utility.cpp')
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp50
1 files changed, 22 insertions, 28 deletions
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index b6b94aa84e..c486a76706 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -93,23 +93,20 @@ ByteString PDF_NameDecode(const ByteStringView& bstr) {
if (!bstr.Contains('#'))
return ByteString(bstr);
- size_t src_size = bstr.GetLength();
- size_t out_index = 0;
+ int size = bstr.GetLength();
ByteString result;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> pDest = result.GetBuffer(src_size);
- for (size_t i = 0; i < src_size; i++) {
- if (bstr[i] == '#' && i < src_size - 2) {
- pDest[out_index++] = FXSYS_HexCharToInt(bstr[i + 1]) * 16 +
- FXSYS_HexCharToInt(bstr[i + 2]);
- i += 2;
- } else {
- pDest[out_index++] = bstr[i];
- }
+ char* pDestStart = result.GetBuffer(size);
+ char* pDest = pDestStart;
+ for (int i = 0; i < size; i++) {
+ if (bstr[i] == '#' && i < size - 2) {
+ *pDest++ = FXSYS_HexCharToInt(bstr[i + 1]) * 16 +
+ FXSYS_HexCharToInt(bstr[i + 2]);
+ i += 2;
+ } else {
+ *pDest++ = bstr[i];
}
}
- result.ReleaseBuffer(out_index);
+ result.ReleaseBuffer(static_cast<size_t>(pDest - pDestStart));
return result;
}
@@ -131,23 +128,20 @@ ByteString PDF_NameEncode(const ByteString& orig) {
return orig;
ByteString res;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> dest_buf = res.GetBuffer(dest_len);
- dest_len = 0;
- for (i = 0; i < src_len; i++) {
- uint8_t ch = src_buf[i];
- if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch == '#' ||
- PDFCharIsDelimiter(ch)) {
- dest_buf[dest_len++] = '#';
- FXSYS_IntToTwoHexChars(ch, &dest_buf[dest_len]);
- dest_len += 2;
- continue;
- }
+ char* dest_buf = res.GetBuffer(dest_len);
+ dest_len = 0;
+ for (i = 0; i < src_len; i++) {
+ uint8_t ch = src_buf[i];
+ if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch == '#' ||
+ PDFCharIsDelimiter(ch)) {
+ dest_buf[dest_len++] = '#';
+ FXSYS_IntToTwoHexChars(ch, dest_buf + dest_len);
+ dest_len += 2;
+ } else {
dest_buf[dest_len++] = ch;
}
- dest_buf[dest_len] = 0;
}
+ dest_buf[dest_len] = 0;
res.ReleaseBuffer(res.GetStringLength());
return res;
}