summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-03 15:08:31 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-03 15:08:31 -0500
commitda06e60fb5a095a91c9a4f509466667878624cb3 (patch)
treecf9af9e6cc40e05cdbcf3ee7271ccc684e805f20
parente0e922db5fb77df9a5a9cc802096f484ed21da1c (diff)
downloadpdfium-da06e60fb5a095a91c9a4f509466667878624cb3.tar.xz
Revert "Revert "Revert "Cleanup some numeric code."""
This reverts commit e0e922db5fb77df9a5a9cc802096f484ed21da1c. Broke Windows build. FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fxcrt\fxcrt.fx_basic_gcc.obj.rsp /c ..\..\core\src\fxcrt\fx_basic_gcc.cpp /Foobj\core\src\fxcrt\fxcrt.fx_basic_gcc.obj /Fdobj\fxcrt.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(28) : error C2220: warning treated as error - no 'object' file generated e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(75) : see reference to function template instantiation 'T FXSYS_StrToInt<int32_t,const FX_WCHAR*>(STR_T)' being compiled with [ T=int32_t , STR_T=const FX_WCHAR * ] e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(28) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fpdftext\fpdftext.fpdf_text.obj.rsp /c ..\..\core\src\fpdftext\fpdf_text.cpp /Foobj\core\src\fpdftext\fpdftext.fpdf_text.obj /Fdobj\fpdftext.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text.cpp(439) : error C2039: 'isdigit' : is not a member of 'std' FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fxcrt\fxcrt.fx_basic_wstring.obj.rsp /c ..\..\core\src\fxcrt\fx_basic_wstring.cpp /Foobj\core\src\fxcrt\fxcrt.fx_basic_wstring.obj /Fdobj\fxcrt.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(973) : error C2220: warning treated as error - no 'object' file generated e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(973) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(981) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fpdftext\fpdftext.fpdf_text_int.obj.rsp /c ..\..\core\src\fpdftext\fpdf_text_int.cpp /Foobj\core\src\fpdftext\fpdftext.fpdf_text_int.obj /Fdobj\fpdftext.cc.pdb e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text_int.cpp(2436) : error C2039: 'isdigit' : is not a member of 'std' e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text_int.cpp(2440) : error C2039: 'isdigit' : is not a member of 'std' ninja: build stopped: subcommand failed. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1431683008 .
-rw-r--r--BUILD.gn1
-rw-r--r--core/include/fxcrt/fx_ext.h30
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp51
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp44
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp1
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp64
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp32
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp163
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp17
-rw-r--r--core/src/fpdftext/fpdf_text.cpp4
-rw-r--r--core/src/fpdftext/fpdf_text_int.cpp5
-rw-r--r--core/src/fxcodec/codec/fx_codec.cpp48
-rw-r--r--core/src/fxcrt/fx_basic_bstring.cpp9
-rw-r--r--core/src/fxcrt/fx_basic_gcc.cpp16
-rw-r--r--core/src/fxcrt/fx_basic_util.cpp20
-rw-r--r--core/src/fxcrt/fx_basic_wstring.cpp14
-rw-r--r--core/src/fxcrt/fx_extension.cpp16
-rw-r--r--core/src/fxcrt/fx_extension_unittest.cpp19
-rw-r--r--core/src/fxcrt/fx_xml_parser.cpp9
-rw-r--r--fpdfsdk/src/fsdk_baseannot.cpp42
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp5
-rw-r--r--fpdfsdk/src/javascript/util.cpp7
-rw-r--r--pdfium.gyp1
23 files changed, 345 insertions, 273 deletions
diff --git a/BUILD.gn b/BUILD.gn
index d9beb039f7..53d234a94d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -724,7 +724,6 @@ test("pdfium_unittests") {
"core/src/fxcrt/fx_basic_memmgr_unittest.cpp",
"core/src/fxcrt/fx_basic_wstring_unittest.cpp",
"core/src/fxcrt/fx_bidi_unittest.cpp",
- "core/src/fxcrt/fx_extension_unittest.cpp",
"core/src/fxcrt/fx_system_unittest.cpp",
"third_party/base/nonstd_unique_ptr_unittest.cpp",
]
diff --git a/core/include/fxcrt/fx_ext.h b/core/include/fxcrt/fx_ext.h
index 4cea13c9fd..c24955fb7c 100644
--- a/core/include/fxcrt/fx_ext.h
+++ b/core/include/fxcrt/fx_ext.h
@@ -7,10 +7,12 @@
#ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_
#define CORE_INCLUDE_FXCRT_FX_EXT_H_
-#include <cctype>
-
#include "fx_system.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
FX_FLOAT FXSYS_tan(FX_FLOAT a);
FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
@@ -36,19 +38,6 @@ inline int32_t FXSYS_toupper(int32_t ch) {
return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
}
-inline int FXSYS_toHexDigit(char c) {
- if (!std::isxdigit(c))
- return 0;
- char upchar = std::toupper(c);
- return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
-}
-
-inline int FXSYS_toDecimalDigit(char c) {
- if (!std::isdigit(c))
- return 0;
- return c - '0';
-}
-
FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr,
int32_t iLength,
FX_BOOL bIgnoreCase = FALSE);
@@ -56,6 +45,13 @@ FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
int32_t iLength,
FX_BOOL bIgnoreCase = FALSE);
+#ifdef __cplusplus
+}
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void* FX_Random_MT_Start(FX_DWORD dwSeed);
FX_DWORD FX_Random_MT_Generate(void* pContext);
@@ -67,7 +63,9 @@ void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount);
void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount);
void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount);
-
+#ifdef __cplusplus
+}
+#endif
template <class baseType>
class CFX_SSortTemplate {
public:
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 2d5e9780ad..0529d3d35b 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -8,7 +8,6 @@
#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"
@@ -514,19 +513,32 @@ 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 && std::isxdigit(buf[i]); ++i)
- result = result * 16 + FXSYS_toHexDigit(buf[i]);
+ 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;
+ }
return result;
}
-
- for (int i = 0; i < len && std::isdigit(buf[i]); ++i)
- result = result * 10 + FXSYS_toDecimalDigit(buf[i]);
-
+ for (int i = 0; i < len; i++) {
+ if (buf[i] < '0' || buf[i] > '9') {
+ break;
+ }
+ result = result * 10 + buf[i] - '0';
+ }
return result;
}
static CFX_WideString StringDataAdd(CFX_WideString str) {
@@ -553,15 +565,26 @@ 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 && std::isxdigit(buf[i]); ++i) {
- ch = ch * 16 + FXSYS_toHexDigit(buf[i]);
+ 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;
+
byte_pos++;
if (byte_pos == 4) {
result += ch;
@@ -571,6 +594,8 @@ 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 2d1834c096..43125d717a 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -7,7 +7,6 @@
#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"
@@ -699,17 +698,30 @@ 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() && std::isxdigit(word.GetAt(i)); ++i)
- num = num * 16 + FXSYS_toHexDigit(word.GetAt(i));
- return num;
+ 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 = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i)
- num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i));
return num;
}
@@ -733,7 +745,13 @@ 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);
- range.m_Lower[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2);
+ 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;
}
FX_DWORD size = second.GetLength();
@@ -744,7 +762,13 @@ 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';
- range.m_Upper[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2);
+ 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;
}
return true;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 72c999e9fc..e095414ffe 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -7,7 +7,6 @@
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_serial.h"
-#include "../../../include/fxcrt/fx_ext.h"
#include "pageint.h"
#define REQUIRE_PARAMS(count) \
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index 5e312e3eec..187d6152e9 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -7,7 +7,6 @@
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fxcodec/fx_codec.h"
-#include "../../../include/fxcrt/fx_ext.h"
#include "pageint.h"
#include <limits.h>
@@ -789,7 +788,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
case 1:
if (ch >= '0' && ch <= '7') {
- iEscCode = FXSYS_toDecimalDigit(ch);
+ iEscCode = ch - '0';
status = 2;
break;
}
@@ -814,7 +813,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
case 2:
if (ch >= '0' && ch <= '7') {
- iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
+ iEscCode = iEscCode * 8 + ch - '0';
status = 3;
} else {
buf.AppendChar(iEscCode);
@@ -824,7 +823,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
case 3:
if (ch >= '0' && ch <= '7') {
- iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
+ iEscCode = iEscCode * 8 + ch - '0';
buf.AppendChar(iEscCode);
status = 0;
} else {
@@ -857,33 +856,50 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() {
if (!PositionIsInBounds())
return CFX_ByteString();
+ int ch = m_pBuf[m_Pos++];
CFX_ByteTextBuf buf;
- bool bFirst = true;
+ FX_BOOL bFirst = TRUE;
int code = 0;
- while (PositionIsInBounds()) {
- int ch = m_pBuf[m_Pos++];
-
- if (ch == '>')
+ while (1) {
+ if (ch == '>') {
break;
-
- if (!std::isxdigit(ch))
- continue;
-
- int val = FXSYS_toHexDigit(ch);
- if (bFirst) {
- code = val * 16;
- } else {
- code += val;
- buf.AppendByte((uint8_t)code);
}
- bFirst = !bFirst;
+ if (ch >= '0' && ch <= '9') {
+ if (bFirst) {
+ code = (ch - '0') * 16;
+ } else {
+ code += ch - '0';
+ buf.AppendChar((char)code);
+ }
+ bFirst = !bFirst;
+ } else if (ch >= 'A' && ch <= 'F') {
+ if (bFirst) {
+ code = (ch - 'A' + 10) * 16;
+ } else {
+ code += ch - 'A' + 10;
+ buf.AppendChar((char)code);
+ }
+ bFirst = !bFirst;
+ } else if (ch >= 'a' && ch <= 'f') {
+ if (bFirst) {
+ code = (ch - 'a' + 10) * 16;
+ } else {
+ code += ch - 'a' + 10;
+ buf.AppendChar((char)code);
+ }
+ bFirst = !bFirst;
+ }
+ if (!PositionIsInBounds())
+ break;
+
+ ch = m_pBuf[m_Pos++];
}
- if (!bFirst)
+ if (!bFirst) {
buf.AppendChar((char)code);
-
- if (buf.GetLength() > MAX_STRING_LENGTH)
+ }
+ if (buf.GetLength() > MAX_STRING_LENGTH) {
return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH);
-
+ }
return buf.GetByteString();
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 3ea554b2d8..e68fcb6800 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -8,7 +8,6 @@
#include "../../../include/fpdfapi/fpdf_parser.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fxcodec/fx_codec.h"
-#include "../../../include/fxcrt/fx_ext.h"
#define _STREAM_MAX_SIZE_ 20 * 1024 * 1024
@@ -129,32 +128,37 @@ FX_DWORD HexDecode(const uint8_t* src_buf,
}
dest_buf = FX_Alloc(uint8_t, i / 2 + 1);
dest_size = 0;
- bool bFirst = true;
+ FX_BOOL bFirstDigit = TRUE;
for (i = 0; i < src_size; i++) {
uint8_t ch = src_buf[i];
if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t')
continue;
- if (ch == '>') {
- ++i;
+ int digit;
+ if (ch <= '9' && ch >= '0') {
+ digit = ch - '0';
+ } else if (ch <= 'f' && ch >= 'a') {
+ digit = ch - 'a' + 10;
+ } else if (ch <= 'F' && ch >= 'A') {
+ digit = ch - 'A' + 10;
+ } else if (ch == '>') {
+ i++;
break;
- }
- if (!std::isxdigit(ch))
+ } else {
continue;
-
- int digit = FXSYS_toHexDigit(ch);
- if (bFirst)
+ }
+ if (bFirstDigit) {
dest_buf[dest_size] = digit * 16;
- else
+ } else {
dest_buf[dest_size++] += digit;
-
- bFirst = !bFirst;
+ }
+ bFirstDigit = !bFirstDigit;
}
- if (!bFirst)
+ if (!bFirstDigit) {
dest_size++;
+ }
return i;
}
-
FX_DWORD RunLengthDecode(const uint8_t* src_buf,
FX_DWORD src_size,
uint8_t*& dest_buf,
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 949c3a4f6f..f5ada7c6eb 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -13,7 +13,6 @@
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_parser.h"
-#include "../../../include/fxcrt/fx_ext.h"
#include "../../../include/fxcrt/fx_safe_types.h"
#include "../fpdf_page/pageint.h"
#include "parser_int.h"
@@ -164,83 +163,85 @@ FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess,
m_bXRefStream = FALSE;
m_LastXRefOffset = 0;
m_bOwnFileRead = bOwnFileRead;
-
int32_t offset = GetHeaderOffset(pFileAccess);
if (offset == -1) {
- if (bOwnFileRead && pFileAccess)
+ if (bOwnFileRead && pFileAccess) {
pFileAccess->Release();
+ }
return PDFPARSE_ERROR_FORMAT;
}
m_Syntax.InitParser(pFileAccess, offset);
-
uint8_t ch;
- if (!m_Syntax.GetCharAt(5, ch))
+ if (!m_Syntax.GetCharAt(5, ch)) {
return PDFPARSE_ERROR_FORMAT;
- if (std::isdigit(ch))
- m_FileVersion = FXSYS_toDecimalDigit(ch) * 10;
-
- if (!m_Syntax.GetCharAt(7, ch))
+ }
+ if (ch >= '0' && ch <= '9') {
+ m_FileVersion = (ch - '0') * 10;
+ }
+ if (!m_Syntax.GetCharAt(7, ch)) {
return PDFPARSE_ERROR_FORMAT;
- if (std::isdigit(ch))
- m_FileVersion += FXSYS_toDecimalDigit(ch);
-
- if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9)
+ }
+ if (ch >= '0' && ch <= '9') {
+ m_FileVersion += ch - '0';
+ }
+ if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) {
return PDFPARSE_ERROR_FORMAT;
-
+ }
m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9);
- if (!bReParse)
+ if (!bReParse) {
m_pDocument = new CPDF_Document(this);
-
+ }
FX_BOOL bXRefRebuilt = FALSE;
if (m_Syntax.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, 4096)) {
FX_FILESIZE startxref_offset = m_Syntax.SavePos();
void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(),
m_SortedOffset.GetSize(), sizeof(FX_FILESIZE),
CompareFileSize);
- if (!pResult)
+ if (pResult == NULL) {
m_SortedOffset.Add(startxref_offset);
-
+ }
m_Syntax.GetKeyword();
FX_BOOL bNumber;
CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber);
- if (!bNumber)
+ if (!bNumber) {
return PDFPARSE_ERROR_FORMAT;
-
+ }
m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str);
if (!LoadAllCrossRefV4(m_LastXRefOffset) &&
!LoadAllCrossRefV5(m_LastXRefOffset)) {
- if (!RebuildCrossRef())
+ if (!RebuildCrossRef()) {
return PDFPARSE_ERROR_FORMAT;
-
+ }
bXRefRebuilt = TRUE;
m_LastXRefOffset = 0;
}
} else {
- if (!RebuildCrossRef())
+ if (!RebuildCrossRef()) {
return PDFPARSE_ERROR_FORMAT;
-
+ }
bXRefRebuilt = TRUE;
}
FX_DWORD dwRet = SetEncryptHandler();
- if (dwRet != PDFPARSE_ERROR_SUCCESS)
+ if (dwRet != PDFPARSE_ERROR_SUCCESS) {
return dwRet;
-
+ }
m_pDocument->LoadDoc();
- if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) {
- if (bXRefRebuilt)
+ if (m_pDocument->GetRoot() == NULL || m_pDocument->GetPageCount() == 0) {
+ if (bXRefRebuilt) {
return PDFPARSE_ERROR_FORMAT;
-
+ }
ReleaseEncryptHandler();
- if (!RebuildCrossRef())
+ if (!RebuildCrossRef()) {
return PDFPARSE_ERROR_FORMAT;
-
+ }
dwRet = SetEncryptHandler();
- if (dwRet != PDFPARSE_ERROR_SUCCESS)
+ if (dwRet != PDFPARSE_ERROR_SUCCESS) {
return dwRet;
-
+ }
m_pDocument->LoadDoc();
- if (!m_pDocument->GetRoot())
+ if (m_pDocument->GetRoot() == NULL) {
return PDFPARSE_ERROR_FORMAT;
+ }
}
FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
sizeof(FX_FILESIZE), CompareFileSize);
@@ -249,12 +250,13 @@ FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess,
ReleaseEncryptHandler();
RebuildCrossRef();
RootObjNum = GetRootObjNum();
- if (RootObjNum == 0)
+ if (RootObjNum == 0) {
return PDFPARSE_ERROR_FORMAT;
-
+ }
dwRet = SetEncryptHandler();
- if (dwRet != PDFPARSE_ERROR_SUCCESS)
+ if (dwRet != PDFPARSE_ERROR_SUCCESS) {
return dwRet;
+ }
}
if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
CPDF_Reference* pMetadata =
@@ -458,8 +460,9 @@ FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos,
int32_t offset = FXSYS_atoi(pEntry);
if (offset == 0) {
for (int32_t c = 0; c < 10; c++) {
- if (!std::isdigit(pEntry[c]))
+ if (pEntry[c] < '0' || pEntry[c] > '9') {
return FALSE;
+ }
}
}
m_CrossRef.SetAtGrow(objnum, offset);
@@ -558,8 +561,9 @@ bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos,
FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry);
if (offset == 0) {
for (int32_t c = 0; c < 10; c++) {
- if (!std::isdigit(pEntry[c]))
+ if (pEntry[c] < '0' || pEntry[c] > '9') {
return false;
+ }
}
}
m_CrossRef.SetAtGrow(objnum, offset);
@@ -627,32 +631,28 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
uint8_t byte = buffer[i];
switch (status) {
case 0:
- if (PDFCharIsWhitespace(byte))
+ if (PDFCharIsWhitespace(byte)) {
status = 1;
-
- if (std::isdigit(byte)) {
+ }
+ if (byte <= '9' && byte >= '0') {
--i;
status = 1;
}
-
if (byte == '%') {
inside_index = 0;
status = 9;
}
-
if (byte == '(') {
status = 10;
depth = 1;
}
-
if (byte == '<') {
inside_index = 1;
status = 11;
}
-
- if (byte == '\\')
+ if (byte == '\\') {
status = 13;
-
+ }
if (byte == 't') {
status = 7;
inside_index = 1;
@@ -661,10 +661,10 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
case 1:
if (PDFCharIsWhitespace(byte)) {
break;
- } else if (std::isdigit(byte)) {
+ } else if (byte <= '9' && byte >= '0') {
start_pos = pos + i;
status = 2;
- objnum = FXSYS_toDecimalDigit(byte);
+ objnum = byte - '0';
} else if (byte == 't') {
status = 7;
inside_index = 1;
@@ -677,8 +677,8 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
}
break;
case 2:
- if (std::isdigit(byte)) {
- objnum = objnum * 10 + FXSYS_toDecimalDigit(byte);
+ if (byte <= '9' && byte >= '0') {
+ objnum = objnum * 10 + byte - '0';
break;
} else if (PDFCharIsWhitespace(byte)) {
status = 3;
@@ -689,10 +689,10 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
}
break;
case 3:
- if (std::isdigit(byte)) {
+ if (byte <= '9' && byte >= '0') {
start_pos1 = pos + i;
status = 4;
- gennum = FXSYS_toDecimalDigit(byte);
+ gennum = byte - '0';
} else if (PDFCharIsWhitespace(byte)) {
break;
} else if (byte == 't') {
@@ -704,8 +704,8 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
}
break;
case 4:
- if (std::isdigit(byte)) {
- gennum = gennum * 10 + FXSYS_toDecimalDigit(byte);
+ if (byte <= '9' && byte >= '0') {
+ gennum = gennum * 10 + byte - '0';
break;
} else if (PDFCharIsWhitespace(byte)) {
status = 5;
@@ -720,9 +720,9 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
inside_index = 1;
} else if (PDFCharIsWhitespace(byte)) {
break;
- } else if (std::isdigit(byte)) {
+ } else if (byte <= '9' && byte >= '0') {
objnum = gennum;
- gennum = FXSYS_toDecimalDigit(byte);
+ gennum = byte - '0';
start_pos = start_pos1;
start_pos1 = pos + i;
status = 4;
@@ -1863,7 +1863,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() {
break;
case 1:
if (ch >= '0' && ch <= '7') {
- iEscCode = FXSYS_toDecimalDigit(ch);
+ iEscCode = ch - '0';
status = 2;
break;
}
@@ -1888,7 +1888,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() {
break;
case 2:
if (ch >= '0' && ch <= '7') {
- iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
+ iEscCode = iEscCode * 8 + ch - '0';
status = 3;
} else {
buf.AppendChar(iEscCode);
@@ -1898,7 +1898,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() {
break;
case 3:
if (ch >= '0' && ch <= '7') {
- iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
+ iEscCode = iEscCode * 8 + ch - '0';
buf.AppendChar(iEscCode);
status = 0;
} else {
@@ -1923,33 +1923,48 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() {
}
CFX_ByteString CPDF_SyntaxParser::ReadHexString() {
uint8_t ch;
- if (!GetNextChar(ch))
+ if (!GetNextChar(ch)) {
return CFX_ByteString();
-
+ }
CFX_BinaryBuf buf;
- bool bFirst = true;
+ FX_BOOL bFirst = TRUE;
uint8_t code = 0;
while (1) {
- if (ch == '>')
+ if (ch == '>') {
break;
-
- if (std::isxdigit(ch)) {
- int val = FXSYS_toHexDigit(ch);
+ }
+ if (ch >= '0' && ch <= '9') {
+ if (bFirst) {
+ code = (ch - '0') * 16;
+ } else {
+ code += ch - '0';
+ buf.AppendByte((uint8_t)code);
+ }
+ bFirst = !bFirst;
+ } else if (ch >= 'A' && ch <= 'F') {
if (bFirst) {
- code = val * 16;
+ code = (ch - 'A' + 10) * 16;
} else {
- code += val;
+ code += ch - 'A' + 10;
+ buf.AppendByte((uint8_t)code);
+ }
+ bFirst = !bFirst;
+ } else if (ch >= 'a' && ch <= 'f') {
+ if (bFirst) {
+ code = (ch - 'a' + 10) * 16;
+ } else {
+ code += ch - 'a' + 10;
buf.AppendByte((uint8_t)code);
}
bFirst = !bFirst;
}
-
- if (!GetNextChar(ch))
+ if (!GetNextChar(ch)) {
break;
+ }
}
- if (!bFirst)
+ if (!bFirst) {
buf.AppendByte((uint8_t)code);
-
+ }
return buf.GetByteString();
}
void CPDF_SyntaxParser::ToNextLine() {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index 202f02ac77..335101e85b 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -5,7 +5,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../../include/fpdfapi/fpdf_parser.h"
-#include "../../../include/fxcrt/fx_ext.h"
// Indexed by 8-bit character code, contains either:
// 'W' - for whitespace: NUL, TAB, CR, LF, FF, 0x80, 0xff
@@ -280,7 +279,18 @@ FX_BOOL CPDF_SimpleParser::FindTagParam(const CFX_ByteStringC& token,
}
return FALSE;
}
-
+static int _hex2dec(char ch) {
+ if (ch >= '0' && ch <= '9') {
+ return ch - '0';
+ }
+ if (ch >= 'a' && ch <= 'f') {
+ return ch - 'a' + 10;
+ }
+ if (ch >= 'A' && ch <= 'F') {
+ return ch - 'A' + 10;
+ }
+ return 0;
+}
CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
int size = bstr.GetLength();
const FX_CHAR* pSrc = bstr.GetCStr();
@@ -292,8 +302,7 @@ CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
FX_CHAR* pDest = pDestStart;
for (int i = 0; i < size; i++) {
if (pSrc[i] == '#' && i < size - 2) {
- *pDest++ =
- FXSYS_toHexDigit(pSrc[i + 1]) * 16 + FXSYS_toHexDigit(pSrc[i + 2]);
+ *pDest++ = _hex2dec(pSrc[i + 1]) * 16 + _hex2dec(pSrc[i + 2]);
i += 2;
} else {
*pDest++ = pSrc[i];
diff --git a/core/src/fpdftext/fpdf_text.cpp b/core/src/fpdftext/fpdf_text.cpp
index e9ad338025..9ecbc21bda 100644
--- a/core/src/fpdftext/fpdf_text.cpp
+++ b/core/src/fpdftext/fpdf_text.cpp
@@ -436,8 +436,10 @@ void NormalizeString(CFX_WideString& str) {
static FX_BOOL IsNumber(CFX_WideString& str) {
for (int i = 0; i < str.GetLength(); i++) {
FX_WCHAR ch = str[i];
- if (!std::isdigit(ch) && ch != '-' && ch != '+' && ch != '.' && ch != ' ')
+ if ((ch < '0' || ch > '9') && ch != '-' && ch != '+' && ch != '.' &&
+ ch != ' ') {
return FALSE;
+ }
}
return TRUE;
}
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp
index 4459552c84..9ab09e19e4 100644
--- a/core/src/fpdftext/fpdf_text_int.cpp
+++ b/core/src/fpdftext/fpdf_text_int.cpp
@@ -2433,11 +2433,12 @@ FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText,
}
if ((char_left > 'A' && char_left < 'a') ||
(char_left > 'a' && char_left < 'z') ||
- (char_left > 0xfb00 && char_left < 0xfb06) || std::isdigit(char_left) ||
+ (char_left > 0xfb00 && char_left < 0xfb06) ||
+ (char_left >= '0' && char_left <= '9') ||
(char_right > 'A' && char_right < 'a') ||
(char_right > 'a' && char_right < 'z') ||
(char_right > 0xfb00 && char_right < 0xfb06) ||
- std::isdigit(char_right)) {
+ (char_right >= '0' && char_right <= '9')) {
return FALSE;
}
if (!(('A' > char_left || char_left > 'Z') &&
diff --git a/core/src/fxcodec/codec/fx_codec.cpp b/core/src/fxcodec/codec/fx_codec.cpp
index 08b2d2d985..46f479e0b1 100644
--- a/core/src/fxcodec/codec/fx_codec.cpp
+++ b/core/src/fxcodec/codec/fx_codec.cpp
@@ -9,7 +9,6 @@
#include <cmath>
#include "../../../../third_party/base/logging.h"
-#include "../../../include/fxcrt/fx_ext.h"
#include "../../../include/fxcrt/fx_safe_types.h"
#include "codec_int.h"
@@ -148,20 +147,6 @@ FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf,
FX_DWORD& dest_size) {
return FALSE;
}
-
-#define EXPONENT_DETECT(ptr) \
- for (;; ptr++) { \
- if (!std::isdigit(*ptr)) { \
- if (endptr) \
- *endptr = (char*)ptr; \
- break; \
- } else { \
- exp_ret *= 10; \
- exp_ret += FXSYS_toDecimalDigit(*ptr); \
- continue; \
- } \
- }
-
extern "C" double FXstrtod(const char* nptr, char** endptr) {
double ret = 0.0;
const char* ptr = nptr;
@@ -172,20 +157,20 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) {
return 0.0;
}
for (;; ptr++) {
- if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' '))
+ if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' ')) {
continue;
-
- if (std::isdigit(*ptr)) {
- if (!e_number)
+ }
+ if (*ptr >= '0' && *ptr <= '9') {
+ if (!e_number) {
e_number = 1;
-
+ }
if (!e_point) {
ret *= 10;
- ret += FXSYS_toDecimalDigit(*ptr);
+ ret += (*ptr - '0');
} else {
fra_count++;
fra_ret *= 10;
- fra_ret += FXSYS_toDecimalDigit(*ptr);
+ fra_ret += (*ptr - '0');
}
continue;
}
@@ -203,17 +188,29 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) {
}
}
if (e_number && (*ptr == 'e' || *ptr == 'E')) {
+#define EXPONENT_DETECT(ptr) \
+ for (;; ptr++) { \
+ if (*ptr < '0' || *ptr > '9') { \
+ if (endptr) \
+ *endptr = (char*)ptr; \
+ break; \
+ } else { \
+ exp_ret *= 10; \
+ exp_ret += (*ptr - '0'); \
+ continue; \
+ } \
+ }
exp_ptr = ptr++;
if (*ptr == '+' || *ptr == '-') {
exp_sig = (*ptr++ == '+') ? 1 : -1;
- if (!std::isdigit(*ptr)) {
+ if (*ptr < '0' || *ptr > '9') {
if (endptr) {
*endptr = (char*)exp_ptr;
}
break;
}
EXPONENT_DETECT(ptr);
- } else if (std::isdigit(*ptr)) {
+ } else if (*ptr >= '0' && *ptr <= '9') {
EXPONENT_DETECT(ptr);
} else {
if (endptr) {
@@ -221,6 +218,7 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) {
}
break;
}
+#undef EXPONENT_DETECT
break;
}
if (ptr != nptr && !e_number) {
@@ -249,8 +247,6 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) {
}
return is_negative ? -ret : ret;
}
-#undef EXPONENT_DETECT
-
FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf,
FX_DWORD src_size,
uint8_t*& dest_buf,
diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp
index 1b9d7a0344..c706912d9d 100644
--- a/core/src/fxcrt/fx_basic_bstring.cpp
+++ b/core/src/fxcrt/fx_basic_bstring.cpp
@@ -5,7 +5,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <stddef.h> // For offsetof().
-#include <cctype>
#include "../../include/fxcrt/fx_basic.h"
#include "../../../third_party/base/numerics/safe_math.h"
@@ -494,8 +493,8 @@ void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) {
}
if (nWidth == 0) {
nWidth = FXSYS_atoi(lpsz);
- while (std::isdigit(*lpsz))
- lpsz++;
+ for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++)
+ ;
}
if (nWidth < 0 || nWidth > 128 * 1024) {
lpszFormat = "Bad width";
@@ -510,8 +509,8 @@ void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) {
lpsz++;
} else {
nPrecision = FXSYS_atoi(lpsz);
- while (std::isdigit(*lpsz))
- lpsz++;
+ for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++)
+ ;
}
}
if (nPrecision < 0 || nPrecision > 128 * 1024) {
diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp
index 250079913c..6f17482156 100644
--- a/core/src/fxcrt/fx_basic_gcc.cpp
+++ b/core/src/fxcrt/fx_basic_gcc.cpp
@@ -5,7 +5,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <limits>
-#include <cctype>
#include "../../include/fxcrt/fx_ext.h"
#include "../../include/fxcrt/fx_string.h"
@@ -13,19 +12,22 @@
template <class T, class STR_T>
T FXSYS_StrToInt(STR_T str) {
FX_BOOL neg = FALSE;
- if (!str)
+ if (str == NULL) {
return 0;
-
+ }
if (*str == '-') {
neg = TRUE;
str++;
}
T num = 0;
- while (*str && std::isdigit(*str)) {
- if (num > (std::numeric_limits<T>::max() - 9) / 10)
+ while (*str) {
+ if ((*str) < '0' || (*str) > '9') {
break;
-
- num = num * 10 + FXSYS_toDecimalDigit(*str);
+ }
+ if (num > (std::numeric_limits<T>::max() - 9) / 10) {
+ break;
+ }
+ num = num * 10 + (*str) - '0';
str++;
}
return neg ? -num : num;
diff --git a/core/src/fxcrt/fx_basic_util.cpp b/core/src/fxcrt/fx_basic_util.cpp
index 78bdeee693..46a0dec1e5 100644
--- a/core/src/fxcrt/fx_basic_util.cpp
+++ b/core/src/fxcrt/fx_basic_util.cpp
@@ -5,17 +5,12 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
-#include "../../include/fxcrt/fx_ext.h"
-
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
#include <sys/types.h>
#include <dirent.h>
#else
#include <direct.h>
#endif
-
-#include <cctype>
-
CFX_PrivateData::~CFX_PrivateData() {
ClearAll();
}
@@ -105,11 +100,14 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
bNegative = TRUE;
cc++;
}
- while (cc < len && std::isdigit(str[cc])) {
- integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]);
- if (integer < 0)
+ while (cc < len) {
+ if (str[cc] < '0' || str[cc] > '9') {
break;
-
+ }
+ integer = integer * 10 + str[cc] - '0';
+ if (integer < 0) {
+ break;
+ }
cc++;
}
if (bNegative) {
@@ -146,7 +144,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (str[cc] == '.') {
break;
}
- value = value * 10 + FXSYS_toDecimalDigit(str[cc]);
+ value = value * 10 + str[cc] - '0';
cc++;
}
static const FX_FLOAT fraction_scales[] = {
@@ -157,7 +155,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (cc < len && str[cc] == '.') {
cc++;
while (cc < len) {
- value += fraction_scales[scale] * FXSYS_toDecimalDigit(str[cc]);
+ value += fraction_scales[scale] * (str[cc] - '0');
scale++;
if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) {
break;
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index cb94d81196..c097e1fc09 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -5,10 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <stddef.h> // For offsetof().
-#include <cctype>
#include "../../include/fxcrt/fx_basic.h"
-#include "../../include/fxcrt/fx_ext.h"
#include "../../../third_party/base/numerics/safe_math.h"
// static
@@ -767,8 +765,8 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) {
}
if (nWidth == 0) {
nWidth = FXSYS_wtoi(lpsz);
- while (std::isdigit(*lpsz))
- ++lpsz;
+ for (; *lpsz != 0 && (*lpsz) <= '9' && (*lpsz) >= '0'; lpsz++)
+ ;
}
if (nWidth < 0 || nWidth > 128 * 1024) {
lpszFormat = L"Bad width";
@@ -783,8 +781,8 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) {
lpsz++;
} else {
nPrecision = FXSYS_wtoi(lpsz);
- while (std::isdigit(*lpsz))
- ++lpsz;
+ for (; *lpsz != 0 && (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++)
+ ;
}
}
if (nPrecision < 0 || nPrecision > 128 * 1024) {
@@ -970,7 +968,7 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) {
if (str[cc] == '.') {
break;
}
- integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]);
+ integer = integer * 10 + str[cc] - '0';
cc++;
}
FX_FLOAT fraction = 0;
@@ -978,7 +976,7 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) {
cc++;
FX_FLOAT scale = 0.1f;
while (cc < len) {
- fraction += scale * FXSYS_toDecimalDigit(str[cc]);
+ fraction += scale * (str[cc] - '0');
scale *= 0.1f;
cc++;
}
diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp
index 4951fbde9c..d64a06d08b 100644
--- a/core/src/fxcrt/fx_extension.cpp
+++ b/core/src/fxcrt/fx_extension.cpp
@@ -7,7 +7,6 @@
#include "../../include/fxcrt/fx_basic.h"
#include "../../include/fxcrt/fx_ext.h"
#include "extension.h"
-
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
#include <wincrypt.h>
#else
@@ -51,7 +50,9 @@ IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer,
IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive) {
return new CFX_MemoryStream(bConsecutive);
}
-
+#ifdef __cplusplus
+extern "C" {
+#endif
FX_FLOAT FXSYS_tan(FX_FLOAT a) {
return (FX_FLOAT)tan(a);
}
@@ -188,7 +189,12 @@ FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
}
return dwHashCode;
}
-
+#ifdef __cplusplus
+}
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
void* FX_Random_MT_Start(FX_DWORD dwSeed) {
FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1);
pContext->mt[0] = dwSeed;
@@ -291,4 +297,6 @@ void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) {
FX_Random_GenerateBase(pBuffer, iCount);
#endif
}
-
+#ifdef __cplusplus
+}
+#endif
diff --git a/core/src/fxcrt/fx_extension_unittest.cpp b/core/src/fxcrt/fx_extension_unittest.cpp
deleted file mode 100644
index 2cadbbfede..0000000000
--- a/core/src/fxcrt/fx_extension_unittest.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2015 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-#include "../../include/fxcrt/fx_ext.h"
-
-TEST(fxcrt, FXSYS_toHexDigit) {
- EXPECT_EQ(10, FXSYS_toHexDigit('a'));
- EXPECT_EQ(10, FXSYS_toHexDigit('A'));
- EXPECT_EQ(7, FXSYS_toHexDigit('7'));
- EXPECT_EQ(0, FXSYS_toHexDigit('i'));
-}
-
-TEST(fxcrt, FXSYS_toDecimalDigit) {
- EXPECT_EQ(7, FXSYS_toDecimalDigit('7'));
- EXPECT_EQ(0, FXSYS_toDecimalDigit('a'));
-}
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp
index 845fd84cfd..dc59ded2b7 100644
--- a/core/src/fxcrt/fx_xml_parser.cpp
+++ b/core/src/fxcrt/fx_xml_parser.cpp
@@ -5,9 +5,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_xml.h"
-#include "../../include/fxcrt/fx_ext.h"
#include "xml_int.h"
-
CXML_Parser::~CXML_Parser() {
if (m_bOwnedStream) {
m_pDataAcc->Release();
@@ -228,8 +226,9 @@ FX_DWORD CXML_Parser::GetCharRef() {
iState = 10;
break;
}
- if (g_FXCRT_XML_IsDigital(ch))
- code = code * 10 + FXSYS_toDecimalDigit(ch);
+ if (g_FXCRT_XML_IsDigital(ch)) {
+ code = code * 10 + ch - '0';
+ }
break;
case 4:
m_dwIndex++;
@@ -241,7 +240,7 @@ FX_DWORD CXML_Parser::GetCharRef() {
g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_HexChar;
if (nHex) {
if (nHex == FXCRTM_XML_CHARTYPE_HexDigital) {
- code = (code << 4) + FXSYS_toDecimalDigit(ch);
+ code = (code << 4) + ch - '0';
} else if (nHex == FXCRTM_XML_CHARTYPE_HexLowerLetter) {
code = (code << 4) + ch - 87;
} else {
diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp
index d0151fbeb2..c6731e6f56 100644
--- a/fpdfsdk/src/fsdk_baseannot.cpp
+++ b/fpdfsdk/src/fsdk_baseannot.cpp
@@ -4,7 +4,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "../../core/include/fxcrt/fx_ext.h"
#include "../include/fsdk_define.h"
#include "../include/fsdk_mgr.h"
#include "../include/fsdk_baseannot.h"
@@ -220,9 +219,12 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
int i = 0;
int j, k;
FX_CHAR ch;
- while (i < strLength && !std::isdigit(dtStr[i]))
- ++i;
-
+ while (i < strLength) {
+ ch = dtStr[i];
+ if (ch >= '0' && ch <= '9')
+ break;
+ i++;
+ }
if (i >= strLength)
return *this;
@@ -230,9 +232,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 4) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
@@ -244,9 +246,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 2) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
@@ -258,9 +260,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 2) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
@@ -272,9 +274,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 2) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
@@ -286,9 +288,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 2) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
@@ -300,9 +302,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 2) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
@@ -321,9 +323,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 2) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
@@ -338,9 +340,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
k = 0;
while (i < strLength && j < 2) {
ch = dtStr[i];
- k = k * 10 + FXSYS_toDecimalDigit(ch);
+ k = k * 10 + ch - '0';
j++;
- if (!std::isdigit(ch))
+ if (ch < '0' || ch > '9')
break;
i++;
}
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 7ede42db13..e898214cd8 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -6,7 +6,6 @@
#include "PublicMethods.h"
-#include "../../../core/include/fxcrt/fx_ext.h"
#include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment.
#include "../../include/javascript/IJavaScript.h"
#include "Field.h"
@@ -117,7 +116,7 @@ FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) {
}
FX_BOOL CJS_PublicMethods::IsDigit(char ch) {
- return std::isdigit(ch);
+ return (ch >= '0' && ch <= '9');
}
FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) {
@@ -397,7 +396,7 @@ int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,
FX_WCHAR c = string.GetAt(i);
if (IsDigit((wchar_t)c)) {
- nRet = nRet * 10 + FXSYS_toDecimalDigit(c);
+ nRet = nRet * 10 + (c - '0');
nSkip = i - nStart + 1;
if (nSkip >= nMaxStep)
break;
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index fc94a0e393..14e15c1b6f 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -6,7 +6,6 @@
#include "util.h"
-#include "../../../core/include/fxcrt/fx_ext.h"
#include "../../include/javascript/IJavaScript.h"
#include "JS_Context.h"
#include "JS_Define.h"
@@ -426,7 +425,7 @@ void util::printx(const std::string& cFormat,
break;
case 'X': {
while (itSource < iSize) {
- if (std::isdigit(cSource[itSource]) ||
+ if ((cSource[itSource] >= '0' && cSource[itSource] <= '9') ||
(cSource[itSource] >= 'a' && cSource[itSource] <= 'z') ||
(cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) {
cPurpose += cSource[itSource];
@@ -451,7 +450,7 @@ void util::printx(const std::string& cFormat,
} break;
case '9': {
while (itSource < iSize) {
- if (std::isdigit(cSource[itSource])) {
+ if (cSource[itSource] >= '0' && cSource[itSource] <= '9') {
cPurpose += cSource[itSource];
itSource++;
break;
@@ -532,7 +531,7 @@ int64_t FX_atoi64(const char* nptr) {
total = 0;
while (isdigit(c)) {
- total = 10 * total + FXSYS_toDecimalDigit(c); /* accumulate digit */
+ total = 10 * total + (c - '0'); /* accumulate digit */
c = (int)(unsigned char)*nptr++; /* get next char */
}
diff --git a/pdfium.gyp b/pdfium.gyp
index 30044c98b3..1afadaa672 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -724,7 +724,6 @@
'core/src/fxcrt/fx_basic_memmgr_unittest.cpp',
'core/src/fxcrt/fx_basic_wstring_unittest.cpp',
'core/src/fxcrt/fx_bidi_unittest.cpp',
- 'core/src/fxcrt/fx_extension_unittest.cpp',
'core/src/fxcrt/fx_system_unittest.cpp',
'testing/fx_string_testhelpers.h',
'testing/fx_string_testhelpers.cpp',