Switch to C headers for cctype, cwchar, and cwctype.
Consistently use the C version instead the C++ version. Also remove a
few unused headers along the way.
Change-Id: I39ae57dfd9c4b384e3fe2e625c62ab87aa7300e4
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83950
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cmapparser.cpp b/core/fpdfapi/font/cpdf_cmapparser.cpp
index ee16bfa..fb3810a 100644
--- a/core/fpdfapi/font/cpdf_cmapparser.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/font/cpdf_cmapparser.h"
+#include <ctype.h>
+
#include "core/fpdfapi/cmaps/fpdf_cmaps.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -145,7 +147,7 @@
FX_SAFE_UINT32 num = 0;
if (word[0] == '<') {
- for (size_t i = 1; i < word.GetLength() && std::isxdigit(word[i]); ++i) {
+ for (size_t i = 1; i < word.GetLength() && isxdigit(word[i]); ++i) {
num = num * 16 + FXSYS_HexCharToInt(word[i]);
if (!num.IsValid())
return 0;
@@ -153,7 +155,7 @@
return num.ValueOrDie();
}
- for (size_t i = 0; i < word.GetLength() && std::isdigit(word[i]); ++i) {
+ for (size_t i = 0; i < word.GetLength() && isdigit(word[i]); ++i) {
num = num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word[i]));
if (!num.IsValid())
return 0;
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 9677083..a49e713 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/page/cpdf_streamparser.h"
+#include <ctype.h>
+
#include <algorithm>
#include <memory>
#include <sstream>
@@ -571,7 +573,7 @@
if (ch == '>')
break;
- if (!std::isxdigit(ch))
+ if (!isxdigit(ch))
continue;
int val = FXSYS_HexCharToInt(ch);
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 6b1a7f8..5bc621a 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/parser/cpdf_parser.h"
+#include <ctype.h>
+
#include <algorithm>
#include <utility>
#include <vector>
@@ -135,13 +137,13 @@
if (!m_pSyntax->GetCharAt(5, ch))
return false;
- if (std::isdigit(ch))
+ if (isdigit(ch))
m_FileVersion = FXSYS_DecimalCharToInt(static_cast<wchar_t>(ch)) * 10;
if (!m_pSyntax->GetCharAt(7, ch))
return false;
- if (std::isdigit(ch))
+ if (isdigit(ch))
m_FileVersion += FXSYS_DecimalCharToInt(static_cast<wchar_t>(ch));
return true;
}
@@ -481,7 +483,7 @@
if (offset.ValueOrDie() == 0) {
for (int32_t c = 0; c < 10; c++) {
- if (!std::isdigit(pEntry[c]))
+ if (!isdigit(pEntry[c]))
return false;
}
}
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 6d837a3..601d2ad 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
+#include <ctype.h>
+
#include <algorithm>
#include <sstream>
#include <utility>
@@ -336,7 +338,7 @@
if (ch == '>')
break;
- if (std::isxdigit(ch)) {
+ if (isxdigit(ch)) {
int val = FXSYS_HexCharToInt(ch);
if (bFirst) {
code = val * 16;
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index e0362d4..8c2dc7a 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -6,6 +6,7 @@
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include <ctype.h>
#include <limits.h>
#include <algorithm>
@@ -220,7 +221,7 @@
++i;
break;
}
- if (!std::isxdigit(ch))
+ if (!isxdigit(ch))
continue;
int digit = FXSYS_HexCharToInt(ch);
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index bc91c4c..ebb72a1 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -6,8 +6,8 @@
#include "core/fpdftext/cpdf_textpagefind.h"
-#include <cwchar>
-#include <cwctype>
+#include <wchar.h>
+
#include <vector>
#include "core/fpdftext/cpdf_textpage.h"
@@ -96,7 +96,7 @@
DCHECK(lpszFullString);
while (iSubString--) {
- lpszFullString = std::wcschr(lpszFullString, L' ');
+ lpszFullString = wcschr(lpszFullString, L' ');
if (!lpszFullString)
return pdfium::nullopt;
@@ -105,7 +105,7 @@
lpszFullString++;
}
- const wchar_t* lpchEnd = std::wcschr(lpszFullString, L' ');
+ const wchar_t* lpchEnd = wcschr(lpszFullString, L' ');
int nLen = lpchEnd ? static_cast<int>(lpchEnd - lpszFullString)
: static_cast<int>(wcslen(lpszFullString));
if (nLen < 0)
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index 0830619..ebd766a 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -6,10 +6,10 @@
#include "core/fxcrt/bytestring.h"
+#include <ctype.h>
#include <stddef.h>
#include <algorithm>
-#include <cctype>
#include <sstream>
#include <string>
#include <utility>
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 215c97e..53186fa 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -7,7 +7,6 @@
#include "core/fxcrt/fx_extension.h"
#include <algorithm>
-#include <cwctype>
#include <limits>
#include "core/fxcrt/fx_system.h"
diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h
index 46eea98..40015c8 100644
--- a/core/fxcrt/fx_extension.h
+++ b/core/fxcrt/fx_extension.h
@@ -7,12 +7,10 @@
#ifndef CORE_FXCRT_FX_EXTENSION_H_
#define CORE_FXCRT_FX_EXTENSION_H_
+#include <ctype.h>
#include <math.h>
#include <time.h>
-
-#include <cctype>
-#include <cwctype>
-#include <memory>
+#include <wctype.h>
#if defined(USE_SYSTEM_ICUUC)
#include <unicode/uchar.h>
@@ -75,11 +73,11 @@
}
inline bool FXSYS_IsHexDigit(char c) {
- return !((c & 0x80) || !std::isxdigit(c));
+ return !((c & 0x80) || !isxdigit(c));
}
inline bool FXSYS_IsWideHexDigit(wchar_t c) {
- return !((c & 0xFFFFFF80) || !std::isxdigit(c));
+ return !((c & 0xFFFFFF80) || !isxdigit(c));
}
inline int FXSYS_HexCharToInt(char c) {
@@ -92,16 +90,16 @@
inline int FXSYS_WideHexCharToInt(wchar_t c) {
if (!FXSYS_IsWideHexDigit(c))
return 0;
- char upchar = std::toupper(static_cast<char>(c));
+ char upchar = toupper(static_cast<char>(c));
return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
}
inline bool FXSYS_IsDecimalDigit(char c) {
- return !((c & 0x80) || !std::isdigit(c));
+ return !((c & 0x80) || !isdigit(c));
}
inline bool FXSYS_IsDecimalDigit(wchar_t c) {
- return !((c & 0xFFFFFF80) || !std::iswdigit(c));
+ return !((c & 0xFFFFFF80) || !iswdigit(c));
}
inline int FXSYS_DecimalCharToInt(char c) {
diff --git a/core/fxcrt/fx_number.cpp b/core/fxcrt/fx_number.cpp
index d268fa0..929c647 100644
--- a/core/fxcrt/fx_number.cpp
+++ b/core/fxcrt/fx_number.cpp
@@ -6,6 +6,8 @@
#include "core/fxcrt/fx_number.h"
+#include <ctype.h>
+
#include <limits>
#include "core/fxcrt/fx_extension.h"
@@ -50,9 +52,9 @@
cc++;
}
- for (; cc < strc.GetLength() && std::isdigit(strc[cc]); ++cc) {
+ for (; cc < strc.GetLength() && isdigit(strc[cc]); ++cc) {
// Deliberately not using FXSYS_DecimalCharToInt() in a tight loop to avoid
- // a duplicate std::isdigit() call. Note that the order of operation is
+ // a duplicate isdigit() call. Note that the order of operation is
// important to avoid unintentional overflows.
unsigned_val = unsigned_val * 10 + (strc[cc] - '0');
}
diff --git a/core/fxcrt/string_view_template.h b/core/fxcrt/string_view_template.h
index 1694347..b8a1eb5 100644
--- a/core/fxcrt/string_view_template.h
+++ b/core/fxcrt/string_view_template.h
@@ -7,8 +7,9 @@
#ifndef CORE_FXCRT_STRING_VIEW_TEMPLATE_H_
#define CORE_FXCRT_STRING_VIEW_TEMPLATE_H_
+#include <ctype.h>
+
#include <algorithm>
-#include <cctype>
#include <iterator>
#include <type_traits>
#include <vector>
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index b7ac000..b38503f 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -10,8 +10,6 @@
#include <string.h>
#include <algorithm>
-#include <cctype>
-#include <cwctype>
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 9008e12..146c78b 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -7,7 +7,6 @@
#include "core/fxcrt/xml/cfx_xmlparser.h"
#include <algorithm>
-#include <cwctype>
#include <iterator>
#include <stack>
#include <utility>
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 65bd92c..9b2300b 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -7,7 +7,6 @@
#include <limits.h>
#include <algorithm>
-#include <cwchar>
#include <memory>
#include <string>
#include <vector>
diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp
index 4031e0e..b37f060 100644
--- a/fxbarcode/oned/BC_OnedCode128Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp
@@ -22,7 +22,8 @@
#include "fxbarcode/oned/BC_OnedCode128Writer.h"
-#include <cctype>
+#include <ctype.h>
+
#include <memory>
#include "core/fxcrt/fx_memory_wrappers.h"
@@ -187,12 +188,12 @@
while (position < contents.GetLength()) {
int32_t patternIndex;
char ch = contents[position];
- if (std::isdigit(ch)) {
+ if (isdigit(ch)) {
patternIndex = FXSYS_atoi(
contents.Substr(position, contents.IsValidIndex(position + 1) ? 2 : 1)
.c_str());
++position;
- if (position < contents.GetLength() && std::isdigit(contents[position]))
+ if (position < contents.GetLength() && isdigit(contents[position]))
++position;
} else {
patternIndex = static_cast<int32_t>(ch);
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 4e20b3e..4bb88e3 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -25,7 +25,6 @@
#include <math.h>
#include <algorithm>
-#include <cwctype>
#include <memory>
#include <vector>
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index 5d0a046..284d2ef 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -25,7 +25,6 @@
#include <math.h>
#include <algorithm>
-#include <cwctype>
#include <memory>
#include <vector>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 8fa8f1d..5c7a91b 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -9,7 +9,6 @@
#include <math.h>
#include <algorithm>
-#include <cwctype>
#include <iomanip>
#include <iterator>
#include <limits>
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index a66581a..f7b4742 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -10,7 +10,6 @@
#include <time.h>
#include <algorithm>
-#include <cwctype>
#include <string>
#include <vector>
diff --git a/fxjs/fx_date_helpers.cpp b/fxjs/fx_date_helpers.cpp
index 74154d6..c0d8998 100644
--- a/fxjs/fx_date_helpers.cpp
+++ b/fxjs/fx_date_helpers.cpp
@@ -8,6 +8,7 @@
#include <math.h>
#include <time.h>
+#include <wctype.h>
#include "build/build_config.h"
#include "core/fxcrt/fx_extension.h"
@@ -159,7 +160,7 @@
size_t FindSubWordLength(const WideString& str, size_t nStart) {
pdfium::span<const wchar_t> data = str.span();
size_t i = nStart;
- while (i < data.size() && std::iswalnum(data[i]))
+ while (i < data.size() && iswalnum(data[i]))
++i;
return i - nStart;
}
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 2cf112e..2127ad6 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -6,11 +6,11 @@
#include "fxjs/xfa/cfxjse_formcalc_context.h"
+#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
-#include <cctype>
#include <sstream>
#include <utility>
@@ -469,7 +469,7 @@
}
bool IsPartOfNumber(char ch) {
- return std::isdigit(ch) || ch == '-' || ch == '.';
+ return isdigit(ch) || ch == '-' || ch == '.';
}
bool IsPartOfNumberW(wchar_t ch) {
@@ -517,7 +517,7 @@
char szYear[5];
szYear[4] = '\0';
for (int32_t i = 0; i < 4; ++i) {
- if (!std::isdigit(pData[i]))
+ if (!isdigit(pData[i]))
return false;
szYear[i] = pData[i];
@@ -530,7 +530,7 @@
iStyle = pData[4] == '-' ? 1 : 0;
size_t iPosOff = iStyle == 0 ? 4 : 5;
- if (!std::isdigit(pData[iPosOff]) || !std::isdigit(pData[iPosOff + 1]))
+ if (!isdigit(pData[iPosOff]) || !isdigit(pData[iPosOff + 1]))
return false;
char szBuffer[3] = {};
@@ -549,7 +549,7 @@
if (pData.size() == 7)
return true;
}
- if (!std::isdigit(pData[iPosOff]) || !std::isdigit(pData[iPosOff + 1]))
+ if (!isdigit(pData[iPosOff]) || !isdigit(pData[iPosOff + 1]))
return false;
szBuffer[0] = pData[iPosOff];
@@ -595,7 +595,7 @@
size_t iZone = 0;
size_t i = 0;
while (i < pData.size()) {
- if (!std::isdigit(pData[i]) && pData[i] != ':') {
+ if (!isdigit(pData[i]) && pData[i] != ':') {
iZone = i;
break;
}
@@ -608,11 +608,11 @@
size_t iPos = 0;
size_t iIndex = 0;
while (iIndex < iZone) {
- if (!std::isdigit(pData[iIndex]))
+ if (!isdigit(pData[iIndex]))
return false;
szBuffer[0] = pData[iIndex];
- if (!std::isdigit(pData[iIndex + 1]))
+ if (!isdigit(pData[iIndex + 1]))
return false;
szBuffer[1] = pData[iIndex + 1];
@@ -654,7 +654,7 @@
char szMilliSeconds[kSubSecondLength + 1];
for (int j = 0; j < kSubSecondLength; ++j) {
char c = pData[iIndex + j];
- if (!std::isdigit(c))
+ if (!isdigit(c))
return false;
szMilliSeconds[j] = c;
}
@@ -682,11 +682,11 @@
}
iPos = 0;
while (iIndex < pData.size()) {
- if (!std::isdigit(pData[iIndex]))
+ if (!isdigit(pData[iIndex]))
return false;
szBuffer[0] = pData[iIndex];
- if (!std::isdigit(pData[iIndex + 1]))
+ if (!isdigit(pData[iIndex + 1]))
return false;
szBuffer[1] = pData[iIndex + 1];
@@ -3524,7 +3524,7 @@
++uVal;
while (uVal < bsUnitTemp.GetLength()) {
- if (!std::isdigit(pChar[uVal]) && pChar[uVal] != '.')
+ if (!isdigit(pChar[uVal]) && pChar[uVal] != '.')
break;
++uVal;
}
diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp
index d6fa54d..19b949b 100644
--- a/xfa/fxfa/parser/cxfa_localevalue.cpp
+++ b/xfa/fxfa/parser/cxfa_localevalue.cpp
@@ -6,7 +6,8 @@
#include "xfa/fxfa/parser/cxfa_localevalue.h"
-#include <cwchar>
+#include <wchar.h>
+
#include <memory>
#include <utility>
#include <vector>