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

Unified Diff: core/src/fxcrt/fx_basic_gcc.cpp

Issue 1757283002: Combine StrToInt methods. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 10 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/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxcrt/fx_basic_gcc.cpp
diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp
index 607f0955707b6fbcf408aad8ccafdc4fd979f362..e2ec939e7d07d8fa3e66b26663b43e26e247a1ce 100644
--- a/core/src/fxcrt/fx_basic_gcc.cpp
+++ b/core/src/fxcrt/fx_basic_gcc.cpp
@@ -11,42 +11,19 @@
#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_string.h"
-template <class T>
-T FXSYS_StrToInt(const FX_CHAR* str) {
- bool neg = false;
+template <typename IntType, typename CharType>
+IntType FXSYS_StrToInt(const CharType* str) {
if (!str)
return 0;
- if (std::numeric_limits<T>::is_signed && *str == '-') {
- neg = true;
+ bool neg = std::numeric_limits<IntType>::is_signed && *str == '-';
+ if (neg)
str++;
- }
- T num = 0;
- while (*str && std::isdigit(*str)) {
- T val = FXSYS_toDecimalDigit(*str);
- if (num > (std::numeric_limits<T>::max() - val) / 10)
- break;
- num = num * 10 + val;
- str++;
- }
- return neg ? -num : num;
-}
-
-template <class T>
-T FXSYS_StrToInt(const FX_WCHAR* str) {
- bool neg = false;
- if (!str)
- return 0;
-
- if (std::numeric_limits<T>::is_signed && *str == '-') {
- neg = true;
- str++;
- }
- T num = 0;
- while (*str && std::iswdigit(*str)) {
- T val = FXSYS_toDecimalDigitWide(*str);
- if (num > (std::numeric_limits<T>::max() - val) / 10)
+ IntType num = 0;
+ while (*str && FXSYS_isDecimalDigit(*str)) {
+ IntType val = FXSYS_toDecimalDigit(*str);
+ if (num > (std::numeric_limits<IntType>::max() - val) / 10)
break;
num = num * 10 + val;
@@ -93,19 +70,19 @@ STR_T FXSYS_IntToStr(T value, STR_T string, int radix) {
extern "C" {
#endif
int32_t FXSYS_atoi(const FX_CHAR* str) {
- return FXSYS_StrToInt<int32_t>(str);
+ return FXSYS_StrToInt<int32_t, FX_CHAR>(str);
}
uint32_t FXSYS_atoui(const FX_CHAR* str) {
return FXSYS_StrToInt<uint32_t>(str);
}
int32_t FXSYS_wtoi(const FX_WCHAR* str) {
- return FXSYS_StrToInt<int32_t>(str);
+ return FXSYS_StrToInt<int32_t, FX_WCHAR>(str);
}
int64_t FXSYS_atoi64(const FX_CHAR* str) {
- return FXSYS_StrToInt<int64_t>(str);
+ return FXSYS_StrToInt<int64_t, FX_CHAR>(str);
}
int64_t FXSYS_wtoi64(const FX_WCHAR* str) {
- return FXSYS_StrToInt<int64_t>(str);
+ return FXSYS_StrToInt<int64_t, FX_WCHAR>(str);
}
const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix) {
return FXSYS_IntToStr<int64_t, uint64_t, FX_CHAR*>(value, str, radix);
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698