summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_font
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-16 13:09:00 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-16 13:09:00 -0500
commit10cfea1fdafc8fcf1edd60bc783e9db9ef6229c0 (patch)
tree3cd1bc8e6a6b33391ea8ad83388a07ca4974f40b /core/src/fpdfapi/fpdf_font
parentec441e67745054ece5e3d736b60fffa2f7f8d20c (diff)
downloadpdfium-10cfea1fdafc8fcf1edd60bc783e9db9ef6229c0.tar.xz
Merge to XFA: Reland "Cleanup some numeric code.""
This reverts commit 0569ab0b11b723d9bca4ddd642b0cf8828c4bdd1. 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=tsepez@chromium.org Review URL: https://codereview.chromium.org/1449873003 . (cherry picked from commit 3f148915d12f54a946a0c0bf526162b79c39d650) Review URL: https://codereview.chromium.org/1452673002 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_font')
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp51
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp44
2 files changed, 23 insertions, 72 deletions
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 9f83da062c..64d6cdce92 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -11,6 +11,7 @@
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
#include "core/include/fpdfapi/fpdf_resource.h"
+#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxge/fx_freetype.h"
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
@@ -518,32 +519,19 @@ FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) {
FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) {
const FX_CHAR* buf = str.GetCStr();
int len = str.GetLength();
- if (len == 0) {
+ if (len == 0)
return 0;
- }
+
int result = 0;
if (buf[0] == '<') {
- for (int i = 1; i < len; i++) {
- int digit;
- if (buf[i] >= '0' && buf[i] <= '9') {
- digit = buf[i] - '0';
- } else if (buf[i] >= 'a' && buf[i] <= 'f') {
- digit = buf[i] - 'a' + 10;
- } else if (buf[i] >= 'A' && buf[i] <= 'F') {
- digit = buf[i] - 'A' + 10;
- } else {
- break;
- }
- result = result * 16 + digit;
- }
+ for (int i = 1; i < len && std::isxdigit(buf[i]); ++i)
+ result = result * 16 + FXSYS_toHexDigit(buf[i]);
return result;
}
- for (int i = 0; i < len; i++) {
- if (buf[i] < '0' || buf[i] > '9') {
- break;
- }
- result = result * 10 + buf[i] - '0';
- }
+
+ for (int i = 0; i < len && std::isdigit(buf[i]); ++i)
+ result = result * 10 + FXSYS_toDecimalDigit(buf[i]);
+
return result;
}
static CFX_WideString StringDataAdd(CFX_WideString str) {
@@ -570,26 +558,15 @@ CFX_WideString CPDF_ToUnicodeMap::StringToWideString(
const CFX_ByteStringC& str) {
const FX_CHAR* buf = str.GetCStr();
int len = str.GetLength();
- if (len == 0) {
+ if (len == 0)
return CFX_WideString();
- }
+
CFX_WideString result;
if (buf[0] == '<') {
int byte_pos = 0;
FX_WCHAR ch = 0;
- for (int i = 1; i < len; i++) {
- int digit;
- if (buf[i] >= '0' && buf[i] <= '9') {
- digit = buf[i] - '0';
- } else if (buf[i] >= 'a' && buf[i] <= 'f') {
- digit = buf[i] - 'a' + 10;
- } else if (buf[i] >= 'A' && buf[i] <= 'F') {
- digit = buf[i] - 'A' + 10;
- } else {
- break;
- }
- ch = ch * 16 + digit;
-
+ for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) {
+ ch = ch * 16 + FXSYS_toHexDigit(buf[i]);
byte_pos++;
if (byte_pos == 4) {
result += ch;
@@ -599,8 +576,6 @@ CFX_WideString CPDF_ToUnicodeMap::StringToWideString(
}
return result;
}
- if (buf[0] == '(') {
- }
return result;
}
void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 65b4b781b1..d4c71085a1 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -9,6 +9,7 @@
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_resource.h"
+#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxge/fx_freetype.h"
#include "core/include/fxge/fx_ge.h"
#include "core/src/fpdfapi/fpdf_cmaps/cmap_int.h"
@@ -699,30 +700,17 @@ void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
m_LastWord = word;
}
+// Static.
FX_DWORD CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) {
int num = 0;
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';
- }
+ for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i)
+ num = num * 16 + FXSYS_toHexDigit(word.GetAt(i));
+ return num;
}
+
+ for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i)
+ num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i));
return num;
}
@@ -746,13 +734,7 @@ bool CPDF_CMapParser::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();
@@ -763,13 +745,7 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range,
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] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2);
}
return true;
}