summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_font/fpdf_font.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.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.cpp')
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp41
1 files changed, 13 insertions, 28 deletions
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 543816b03a..e5389f8c77 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"
@@ -511,32 +512,25 @@ FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) {
static FX_DWORD _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 {
+ if (!std::isxdigit(buf[i]))
break;
- }
- result = result * 16 + digit;
+ result = result * 16 + HexCharToDigit(buf[i]);
}
return result;
}
+
for (int i = 0; i < len; i++) {
- if (buf[i] < '0' || buf[i] > '9') {
+ if (!std::isdigit(buf[i]))
break;
- }
result = result * 10 + buf[i] - '0';
}
+
return result;
}
static CFX_WideString _StringDataAdd(CFX_WideString str) {
@@ -560,25 +554,18 @@ static CFX_WideString _StringDataAdd(CFX_WideString str) {
static CFX_WideString _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 {
+ if (!std::isxdigit(buf[i]))
break;
- }
- ch = ch * 16 + digit;
+
+ ch = ch * 16 + HexCharToDigit(buf[i]);
byte_pos++;
if (byte_pos == 4) {
result += ch;
@@ -588,8 +575,6 @@ static CFX_WideString _StringToWideString(const CFX_ByteStringC& str) {
}
return result;
}
- if (buf[0] == '(') {
- }
return result;
}
void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {