summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-03 14:54:35 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-03 14:54:35 -0500
commite0e922db5fb77df9a5a9cc802096f484ed21da1c (patch)
treed6b3da42c1a28ec150c5cb9fe6b00d8f6af099d5 /core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
parentc9e76c09b9e7901823ac52a3705da235bd2abe24 (diff)
downloadpdfium-e0e922db5fb77df9a5a9cc802096f484ed21da1c.tar.xz
Revert "Revert "Cleanup some numeric code.""
This reverts commit 23d576f0b498bd4f37ef2175916223a2e5ea0324. Cleanup some numeric code. This changes the various comparisons of char >= '0' && char <= '9' and char < '0' || char > '9' to use std::isdigit checks. It also cleans up a handful of hex to digit conversions to call one common method. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1405253007 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index e68fcb6800..3ea554b2d8 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -8,6 +8,7 @@
#include "../../../include/fpdfapi/fpdf_parser.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fxcodec/fx_codec.h"
+#include "../../../include/fxcrt/fx_ext.h"
#define _STREAM_MAX_SIZE_ 20 * 1024 * 1024
@@ -128,37 +129,32 @@ FX_DWORD HexDecode(const uint8_t* src_buf,
}
dest_buf = FX_Alloc(uint8_t, i / 2 + 1);
dest_size = 0;
- FX_BOOL bFirstDigit = TRUE;
+ bool bFirst = true;
for (i = 0; i < src_size; i++) {
uint8_t ch = src_buf[i];
if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t')
continue;
- int digit;
- if (ch <= '9' && ch >= '0') {
- digit = ch - '0';
- } else if (ch <= 'f' && ch >= 'a') {
- digit = ch - 'a' + 10;
- } else if (ch <= 'F' && ch >= 'A') {
- digit = ch - 'A' + 10;
- } else if (ch == '>') {
- i++;
+ if (ch == '>') {
+ ++i;
break;
- } else {
- continue;
}
- if (bFirstDigit) {
+ if (!std::isxdigit(ch))
+ continue;
+
+ int digit = FXSYS_toHexDigit(ch);
+ if (bFirst)
dest_buf[dest_size] = digit * 16;
- } else {
+ else
dest_buf[dest_size++] += digit;
- }
- bFirstDigit = !bFirstDigit;
+
+ bFirst = !bFirst;
}
- if (!bFirstDigit) {
+ if (!bFirst)
dest_size++;
- }
return i;
}
+
FX_DWORD RunLengthDecode(const uint8_t* src_buf,
FX_DWORD src_size,
uint8_t*& dest_buf,