summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-29 14:56:26 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-29 14:56:26 -0400
commit589f7e0a57675efce9810c15a3e9b7c49bf0bc90 (patch)
tree6839707c05c00f227744ffc3788665cb1cb5b7bd /core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
parent6ed0028f1cf12ee53e9e7f657b7ba186c77a42f3 (diff)
downloadpdfium-589f7e0a57675efce9810c15a3e9b7c49bf0bc90.tar.xz
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=thestig@chromium.org Review URL: https://codereview.chromium.org/1415933005 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp')
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp32
1 files changed, 7 insertions, 25 deletions
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 02f0933f36..165ef5bad5 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,22 +191,15 @@ 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 {
+ if (!std::isxdigit(digit))
return num;
- }
- num = num * 16 + digit;
+ num = num * 16 + HexCharToDigit(digit);
}
} else {
for (int i = 0; i < word.GetLength(); i++) {
- if (word.GetAt(i) < '0' || word.GetAt(i) > '9') {
+ if (!std::isdigit(word.GetAt(i)))
return num;
- }
+
num = num * 10 + word.GetAt(i) - '0';
}
}
@@ -231,13 +225,7 @@ 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] = HexCharToDigit(digit1) * 16 + HexCharToDigit(digit2);
}
FX_DWORD size = second.GetLength();
@@ -246,13 +234,7 @@ bool CMap_GetCodeRange(CMap_CodeRange& range,
((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;
+ range.m_Upper[i] = HexCharToDigit(digit1) * 16 + HexCharToDigit(digit2);
}
return true;
}