diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-08-31 15:11:52 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-31 19:30:34 +0000 |
commit | 670c4fdea0acb9663145b96bec1fbf76279781df (patch) | |
tree | 3a28b6244430514b9702e964c24663c3ec31d7fd /core | |
parent | 47a90b894ecca2d3547226169602d7f8729d564f (diff) | |
download | pdfium-670c4fdea0acb9663145b96bec1fbf76279781df.tar.xz |
Cleanup fx_basic_* files
Remove dead code, move code to namespaces where possible, cleanup some
single use items.
Change-Id: Ia734477ceb2105a1ed272463bd8220f1205a7ce9
Reviewed-on: https://pdfium-review.googlesource.com/12732
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fxcrt/fx_basic_gcc.cpp | 57 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_gcc_unittest.cpp | 26 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_util.cpp | 40 | ||||
-rw-r--r-- | core/fxcrt/fx_extension.h | 3 | ||||
-rw-r--r-- | core/fxcrt/fx_stream.h | 1 | ||||
-rw-r--r-- | core/fxcrt/fx_system.h | 10 |
6 files changed, 27 insertions, 110 deletions
diff --git a/core/fxcrt/fx_basic_gcc.cpp b/core/fxcrt/fx_basic_gcc.cpp index 87c2533ab8..12ac399334 100644 --- a/core/fxcrt/fx_basic_gcc.cpp +++ b/core/fxcrt/fx_basic_gcc.cpp @@ -11,6 +11,8 @@ #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_string.h" +namespace { + template <typename IntType, typename CharType> IntType FXSYS_StrToInt(const CharType* str) { if (!str) @@ -79,9 +81,8 @@ STR_T FXSYS_IntToStr(T value, STR_T str, int radix) { return str; } -#ifdef __cplusplus -extern "C" { -#endif +} // namespace + int32_t FXSYS_atoi(const char* str) { return FXSYS_StrToInt<int32_t, char>(str); } @@ -94,47 +95,16 @@ int32_t FXSYS_wtoi(const wchar_t* str) { int64_t FXSYS_atoi64(const char* str) { return FXSYS_StrToInt<int64_t, char>(str); } -int64_t FXSYS_wtoi64(const wchar_t* str) { - return FXSYS_StrToInt<int64_t, wchar_t>(str); -} const char* FXSYS_i64toa(int64_t value, char* str, int radix) { return FXSYS_IntToStr<int64_t, uint64_t, char*>(value, str, radix); } -#ifdef __cplusplus -} -#endif + #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ -#ifdef __cplusplus -extern "C" { -#endif + int FXSYS_GetACP() { return 0; } -uint32_t FXSYS_GetFullPathName(const char* filename, - uint32_t buflen, - char* buf, - char** filepart) { - int srclen = FXSYS_strlen(filename); - if (!buf || (int)buflen < srclen + 1) - return srclen + 1; - - strncpy(buf, filename, buflen); - return srclen; -} - -uint32_t FXSYS_GetModuleFileName(void* hModule, char* buf, uint32_t bufsize) { - return 0xFFFFFFFF; -} - -#ifdef __cplusplus -} -#endif -#endif -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ -#ifdef __cplusplus -extern "C" { -#endif char* FXSYS_strlwr(char* str) { if (!str) { return nullptr; @@ -207,14 +177,7 @@ int FXSYS_wcsicmp(const wchar_t* dst, const wchar_t* src) { char* FXSYS_itoa(int value, char* str, int radix) { return FXSYS_IntToStr<int32_t, uint32_t, char*>(value, str, radix); } -#ifdef __cplusplus -} -#endif -#endif -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ -#ifdef __cplusplus -extern "C" { -#endif + int FXSYS_WideCharToMultiByte(uint32_t codepage, uint32_t dwFlags, const wchar_t* wstr, @@ -248,7 +211,5 @@ int FXSYS_MultiByteToWideChar(uint32_t codepage, } return wlen; } -#ifdef __cplusplus -} -#endif -#endif + +#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ diff --git a/core/fxcrt/fx_basic_gcc_unittest.cpp b/core/fxcrt/fx_basic_gcc_unittest.cpp index 665eede9ff..2960ee58c0 100644 --- a/core/fxcrt/fx_basic_gcc_unittest.cpp +++ b/core/fxcrt/fx_basic_gcc_unittest.cpp @@ -60,7 +60,6 @@ TEST(fxcrt, FXSYS_wtoi) { EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483647")); // The min value. EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483648")); - EXPECT_EQ(9, FXSYS_wtoi64(L"9x9")); // Out of range values. EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483623423412348")); @@ -68,31 +67,6 @@ TEST(fxcrt, FXSYS_wtoi) { EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483652")); } -TEST(fxcrt, FXSYS_wtoi64) { - EXPECT_EQ(0, FXSYS_wtoi64(L"")); - EXPECT_EQ(0, FXSYS_wtoi64(L"0")); - EXPECT_EQ(-1, FXSYS_wtoi64(L"-1")); - EXPECT_EQ(2345, FXSYS_wtoi64(L"2345")); - EXPECT_EQ(-9223372036854775807LL, FXSYS_wtoi64(L"-9223372036854775807")); - // Handle the sign. - EXPECT_EQ(-2345, FXSYS_wtoi64(L"-2345")); - EXPECT_EQ(2345, FXSYS_wtoi64(L"+2345")); - // The max value. - EXPECT_EQ(9223372036854775807LL, FXSYS_wtoi64(L"9223372036854775807")); - // The min value. - EXPECT_EQ(-9223372036854775807LL - 1LL, - FXSYS_wtoi64(L"-9223372036854775808")); - // With invalid char. - EXPECT_EQ(9, FXSYS_wtoi64(L"9x9")); - - // Out of range values. - EXPECT_EQ(9223372036854775807LL, - FXSYS_wtoi64(L"922337203685471234123475807")); - EXPECT_EQ(9223372036854775807LL, FXSYS_wtoi64(L"9223372036854775808")); - EXPECT_EQ(-9223372036854775807LL - 1LL, - FXSYS_wtoi64(L"-9223372036854775810")); -} - TEST(fxcrt, FXSYS_atoui) { EXPECT_EQ(0u, FXSYS_atoui("")); EXPECT_EQ(0u, FXSYS_atoui("0")); diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index 2a9ce05e4b..d8cf087b73 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -11,8 +11,22 @@ #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_stream.h" +#include "core/fxcrt/fx_system.h" #include "third_party/base/ptr_util.h" +namespace { + +const float fraction_scales[] = {0.1f, 0.01f, 0.001f, + 0.0001f, 0.00001f, 0.000001f, + 0.0000001f, 0.00000001f, 0.000000001f, + 0.0000000001f, 0.00000000001f}; + +float FractionalScale(size_t scale_factor, int value) { + return fraction_scales[scale_factor] * value; +} + +} // namespace + bool FX_atonum(const CFX_ByteStringC& strc, void* pData) { if (strc.Contains('.')) { float* pFloat = static_cast<float*>(pData); @@ -70,19 +84,6 @@ bool FX_atonum(const CFX_ByteStringC& strc, void* pData) { return true; } -static const float fraction_scales[] = { - 0.1f, 0.01f, 0.001f, 0.0001f, - 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, - 0.000000001f, 0.0000000001f, 0.00000000001f}; - -int FXSYS_FractionalScaleCount() { - return FX_ArraySize(fraction_scales); -} - -float FXSYS_FractionalScale(size_t scale_factor, int value) { - return fraction_scales[scale_factor] * value; -} - float FX_atof(const CFX_ByteStringC& strc) { if (strc.IsEmpty()) return 0.0; @@ -112,10 +113,9 @@ float FX_atof(const CFX_ByteStringC& strc) { if (cc < len && strc[cc] == '.') { cc++; while (cc < len) { - value += - FXSYS_FractionalScale(scale, FXSYS_DecimalCharToInt(strc.CharAt(cc))); + value += FractionalScale(scale, FXSYS_DecimalCharToInt(strc.CharAt(cc))); scale++; - if (scale == FXSYS_FractionalScaleCount()) + if (scale == FX_ArraySize(fraction_scales)) break; cc++; } @@ -181,14 +181,6 @@ void FX_CloseFolder(FX_FileHandle* handle) { #endif } -wchar_t FX_GetFolderSeparator() { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - return '\\'; -#else - return '/'; -#endif -} - uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) { ASSERT(0 < nbits && nbits <= 32); const uint8_t* dataPtr = &pData[bitpos / 8]; diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h index fbb86fea45..bd20b3969e 100644 --- a/core/fxcrt/fx_extension.h +++ b/core/fxcrt/fx_extension.h @@ -86,9 +86,6 @@ void FXSYS_IntToFourHexChars(uint16_t c, char* buf); size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf); -float FXSYS_FractionalScale(size_t scale_factor, int value); -int FXSYS_FractionalScaleCount(); - void* FX_Random_MT_Start(uint32_t dwSeed); void FX_Random_MT_Close(void* pContext); uint32_t FX_Random_MT_Generate(void* pContext); diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h index 622818173b..abf031dade 100644 --- a/core/fxcrt/fx_stream.h +++ b/core/fxcrt/fx_stream.h @@ -33,7 +33,6 @@ bool FX_GetNextFile(FX_FileHandle* handle, CFX_ByteString* filename, bool* bFolder); void FX_CloseFolder(FX_FileHandle* handle); -wchar_t FX_GetFolderSeparator(); #define FX_FILEMODE_Write 0 #define FX_FILEMODE_ReadOnly 1 diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h index ad7e6bbcd7..1f63e6d9aa 100644 --- a/core/fxcrt/fx_system.h +++ b/core/fxcrt/fx_system.h @@ -162,8 +162,6 @@ extern "C" { #define FXSYS_strupr _strupr #define FXSYS_stricmp _stricmp #define FXSYS_pow(a, b) (float)powf(a, b) -#define FXSYS_GetFullPathName GetFullPathName -#define FXSYS_GetModuleFileName GetModuleFileName size_t FXSYS_wcsftime(wchar_t* strDest, size_t maxsize, const wchar_t* format, @@ -183,7 +181,9 @@ size_t FXSYS_wcsftime(wchar_t* strDest, #define FXSYS_wcslwr _wcslwr #define FXSYS_wcsupr _wcsupr #endif // _NATIVE_WCHAR_T_DEFINED + #else // _FXM_PLATFORM == _FXM_PLATFORM_WINDOWS_ + int FXSYS_GetACP(); char* FXSYS_itoa(int value, char* str, int radix); int FXSYS_WideCharToMultiByte(uint32_t codepage, @@ -200,11 +200,6 @@ int FXSYS_MultiByteToWideChar(uint32_t codepage, int blen, wchar_t* buf, int buflen); -uint32_t FXSYS_GetFullPathName(const char* filename, - uint32_t buflen, - char* buf, - char** filepart); -uint32_t FXSYS_GetModuleFileName(void* hModule, char* buf, uint32_t bufsize); char* FXSYS_strlwr(char* str); char* FXSYS_strupr(char* str); int FXSYS_stricmp(const char*, const char*); @@ -225,7 +220,6 @@ int32_t FXSYS_atoi(const char* str); uint32_t FXSYS_atoui(const char* str); int32_t FXSYS_wtoi(const wchar_t* str); int64_t FXSYS_atoi64(const char* str); -int64_t FXSYS_wtoi64(const wchar_t* str); const char* FXSYS_i64toa(int64_t value, char* str, int radix); int FXSYS_round(float f); #define FXSYS_sqrt2(a, b) (float)sqrt((a) * (a) + (b) * (b)) |