Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp

Issue 1431683008: Revert "Revert "Revert "Cleanup some numeric code.""" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 3ea554b2d869ceacdaf75fd73262d6104fb8b9d5..e68fcb6800a30792db44dc2ec3f56e96c260a882 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -8,7 +8,6 @@
#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
@@ -129,32 +128,37 @@ FX_DWORD HexDecode(const uint8_t* src_buf,
}
dest_buf = FX_Alloc(uint8_t, i / 2 + 1);
dest_size = 0;
- bool bFirst = true;
+ FX_BOOL bFirstDigit = TRUE;
for (i = 0; i < src_size; i++) {
uint8_t ch = src_buf[i];
if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t')
continue;
- if (ch == '>') {
- ++i;
+ 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++;
break;
- }
- if (!std::isxdigit(ch))
+ } else {
continue;
-
- int digit = FXSYS_toHexDigit(ch);
- if (bFirst)
+ }
+ if (bFirstDigit) {
dest_buf[dest_size] = digit * 16;
- else
+ } else {
dest_buf[dest_size++] += digit;
-
- bFirst = !bFirst;
+ }
+ bFirstDigit = !bFirstDigit;
}
- if (!bFirst)
+ if (!bFirstDigit) {
dest_size++;
+ }
return i;
}
-
FX_DWORD RunLengthDecode(const uint8_t* src_buf,
FX_DWORD src_size,
uint8_t*& dest_buf,
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698