summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-03 14:54:35 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-03 14:54:35 -0500
commite0e922db5fb77df9a5a9cc802096f484ed21da1c (patch)
treed6b3da42c1a28ec150c5cb9fe6b00d8f6af099d5 /core/src/fpdfapi/fpdf_font/fpdf_font.cpp
parentc9e76c09b9e7901823ac52a3705da235bd2abe24 (diff)
downloadpdfium-e0e922db5fb77df9a5a9cc802096f484ed21da1c.tar.xz
Revert "Revert "Cleanup some numeric code.""
This reverts commit 23d576f0b498bd4f37ef2175916223a2e5ea0324. 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=tsepez@chromium.org Review URL: https://codereview.chromium.org/1405253007 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_font/fpdf_font.cpp')
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp51
1 files changed, 13 insertions, 38 deletions
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 0529d3d35b..2d5e9780ad 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -8,6 +8,7 @@
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_pageobj.h"
#include "../../../include/fpdfapi/fpdf_resource.h"
+#include "../../../include/fxcrt/fx_ext.h"
#include "../../../include/fxge/fx_freetype.h"
#include "../fpdf_page/pageint.h"
#include "font_int.h"
@@ -513,32 +514,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) {
@@ -565,26 +553,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;
@@ -594,8 +571,6 @@ CFX_WideString CPDF_ToUnicodeMap::StringToWideString(
}
return result;
}
- if (buf[0] == '(') {
- }
return result;
}
void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {