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

Unified Diff: core/src/fpdfapi/fpdf_font/fpdf_font.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
« no previous file with comments | « core/include/fxcrt/fx_ext.h ('k') | core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_font/fpdf_font.cpp
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 543816b03afa47f8d4dbca2eaddd1ce5934dbf4d..33fae3c9f896f2e9f4558608470b6489af721ea0 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,22 @@ 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 {
- break;
- }
- result = result * 16 + digit;
- }
+ for (int i = 1; i < len && !std::isxdigit(buf[i]); ++i)
Tom Sepez 2015/10/29 20:44:26 I don't think you want the ! here.
dsinclair 2015/11/02 15:43:37 Done.
+ result = result * 16 + FXSYS_toHexDigit(buf[i]);
return result;
}
+
for (int i = 0; i < len; i++) {
Tom Sepez 2015/10/29 20:44:26 Lets make the same change here.
dsinclair 2015/11/02 15:43:37 Done.
- if (buf[i] < '0' || buf[i] > '9') {
+ if (!std::isdigit(buf[i]))
break;
- }
- result = result * 10 + buf[i] - '0';
+ result = result * 10 + FXSYS_toDecimalDigit(buf[i]);
}
+
return result;
}
static CFX_WideString _StringDataAdd(CFX_WideString str) {
@@ -560,25 +551,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 + FXSYS_toHexDigit(buf[i]);
byte_pos++;
if (byte_pos == 4) {
result += ch;
@@ -588,8 +572,6 @@ static CFX_WideString _StringToWideString(const CFX_ByteStringC& str) {
}
return result;
}
- if (buf[0] == '(') {
- }
return result;
}
void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
« no previous file with comments | « core/include/fxcrt/fx_ext.h ('k') | core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698