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

Unified Diff: core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.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_old.cpp
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index 1fa27e38051b97ee4ee09225615041f9921dca56..97ac774c8e2ff329c962e1a77ac9cb5409896b51 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -7,6 +7,7 @@
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fxcodec/fx_codec.h"
+#include "../../../include/fxcrt/fx_ext.h"
#include "pageint.h"
#include <limits.h>
@@ -802,7 +803,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
case 1:
if (ch >= '0' && ch <= '7') {
- iEscCode = ch - '0';
+ iEscCode = FXSYS_toDecimalDigit(ch);
status = 2;
break;
}
@@ -827,7 +828,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
case 2:
if (ch >= '0' && ch <= '7') {
- iEscCode = iEscCode * 8 + ch - '0';
+ iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
status = 3;
} else {
buf.AppendChar(iEscCode);
@@ -837,7 +838,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
case 3:
if (ch >= '0' && ch <= '7') {
- iEscCode = iEscCode * 8 + ch - '0';
+ iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
buf.AppendChar(iEscCode);
status = 0;
} else {
@@ -870,50 +871,33 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() {
if (!PositionIsInBounds())
return CFX_ByteString();
- int ch = m_pBuf[m_Pos++];
CFX_ByteTextBuf buf;
- FX_BOOL bFirst = TRUE;
+ bool bFirst = true;
int code = 0;
- while (1) {
- if (ch == '>') {
- break;
- }
- 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 (bFirst) {
- code = (ch - 'a' + 10) * 16;
- } else {
- code += ch - 'a' + 10;
- buf.AppendChar((char)code);
- }
- bFirst = !bFirst;
- }
- if (!PositionIsInBounds())
+ while (PositionIsInBounds()) {
+ int ch = m_pBuf[m_Pos++];
+
+ if (ch == '>')
break;
- ch = m_pBuf[m_Pos++];
+ if (!std::isxdigit(ch))
+ continue;
+
+ int val = FXSYS_toHexDigit(ch);
+ if (bFirst) {
+ code = val * 16;
+ } else {
+ code += val;
+ buf.AppendByte((uint8_t)code);
+ }
+ bFirst = !bFirst;
}
- if (!bFirst) {
+ if (!bFirst)
buf.AppendChar((char)code);
- }
- if (buf.GetLength() > MAX_STRING_LENGTH) {
+
+ if (buf.GetLength() > MAX_STRING_LENGTH)
return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH);
- }
+
return buf.GetByteString();
}

Powered by Google App Engine
This is Rietveld 408576698