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

Unified Diff: core/src/fpdfapi/fpdf_font/fpdf_font_cid.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_font/fpdf_font_cid.cpp
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 02f0933f360089f2677ae74ed1e2664466a0b51a..b136cfe3619af02b6f8749500b40c5d3280daddf 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -7,6 +7,7 @@
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_resource.h"
+#include "../../../include/fxcrt/fx_ext.h"
#include "../../../include/fxge/fx_freetype.h"
#include "../../../include/fxge/fx_ge.h"
#include "../fpdf_cmaps/cmap_int.h"
@@ -190,24 +191,17 @@ FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) {
if (word.GetAt(0) == '<') {
for (int i = 1; i < word.GetLength(); i++) {
uint8_t digit = word.GetAt(i);
- if (digit >= '0' && digit <= '9') {
- digit = digit - '0';
- } else if (digit >= 'a' && digit <= 'f') {
- digit = digit - 'a' + 10;
- } else if (digit >= 'A' && digit <= 'F') {
- digit = digit - 'A' + 10;
- } else {
- return num;
- }
- num = num * 16 + digit;
- }
- } else {
- for (int i = 0; i < word.GetLength(); i++) {
- if (word.GetAt(i) < '0' || word.GetAt(i) > '9') {
- return num;
- }
- num = num * 10 + word.GetAt(i) - '0';
+ if (!std::isxdigit(digit))
+ break;
+ num = num * 16 + FXSYS_toHexDigit(digit);
}
+ return num;
+ }
+
+ for (int i = 0; i < word.GetLength(); i++) {
+ if (!std::isdigit(word.GetAt(i)))
+ break;
+ num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i));
}
return num;
}
@@ -231,28 +225,18 @@ bool CMap_GetCodeRange(CMap_CodeRange& range,
for (i = 0; i < range.m_CharSize; ++i) {
uint8_t digit1 = first.GetAt(i * 2 + 1);
uint8_t digit2 = first.GetAt(i * 2 + 2);
- uint8_t byte = (digit1 >= '0' && digit1 <= '9')
- ? (digit1 - '0')
- : ((digit1 & 0xdf) - 'A' + 10);
- byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
- ? (digit2 - '0')
- : ((digit2 & 0xdf) - 'A' + 10));
- range.m_Lower[i] = byte;
+ range.m_Lower[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2);
}
FX_DWORD size = second.GetLength();
for (i = 0; i < range.m_CharSize; ++i) {
- uint8_t digit1 =
- ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0;
- uint8_t digit2 =
- ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0;
- uint8_t byte = (digit1 >= '0' && digit1 <= '9')
- ? (digit1 - '0')
- : ((digit1 & 0xdf) - 'A' + 10);
- byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
- ? (digit2 - '0')
- : ((digit2 & 0xdf) - 'A' + 10));
- range.m_Upper[i] = byte;
+ uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size)
+ ? second.GetAt((FX_STRSIZE)i * 2 + 1)
+ : '0';
+ uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size)
+ ? second.GetAt((FX_STRSIZE)i * 2 + 2)
+ : '0';
+ range.m_Upper[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2);
}
return true;
}

Powered by Google App Engine
This is Rietveld 408576698