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

Unified Diff: core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp

Issue 1405253007: Revert "Revert "Cleanup some numeric code."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Leftover comments from original CL. Created 5 years, 2 months 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_page/fpdf_page_parser.cpp
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 3057948959807b1e84e336729ad5ee6dc3efe3c2..dd31322744e15d7d2c01492af2ca95826e300ce3 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -7,6 +7,7 @@
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_serial.h"
+#include "../../../include/fxcrt/fx_ext.h"
#include "pageint.h"
#define REQUIRE_PARAMS(count) \
@@ -1534,40 +1535,26 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) {
}
CFX_ByteString _FPDF_ByteStringFromHex(CFX_BinaryBuf& src_buf) {
CFX_ByteTextBuf buf;
- FX_BOOL bFirst = TRUE;
+ bool bFirst = true;
int code = 0;
const uint8_t* str = src_buf.GetBuffer();
FX_DWORD size = src_buf.GetSize();
for (FX_DWORD i = 0; i < size; i++) {
uint8_t ch = str[i];
- if (ch >= '0' && ch <= '9') {
- if (bFirst) {
- code = (ch - '0') * 16;
- } else {
- code += ch - '0';
- buf.AppendChar((char)code);
- }
- bFirst = !bFirst;
- } else if (ch >= 'A' && ch <= 'F') {
- if (bFirst) {
- code = (ch - 'A' + 10) * 16;
- } else {
- code += ch - 'A' + 10;
- buf.AppendChar((char)code);
- }
- bFirst = !bFirst;
- } else if (ch >= 'a' && ch <= 'f') {
+
+ if (std::isxdigit(ch)) {
+ int val = FXSYS_toHexDigit(ch);
if (bFirst) {
- code = (ch - 'a' + 10) * 16;
+ code = val * 16;
} else {
- code += ch - 'a' + 10;
+ code += val;
buf.AppendChar((char)code);
}
bFirst = !bFirst;
}
}
- if (!bFirst) {
+ if (!bFirst)
buf.AppendChar((char)code);
- }
+
return buf.GetByteString();
}

Powered by Google App Engine
This is Rietveld 408576698