From aeb44f8c4675141e170329d5093b251fbfad8023 Mon Sep 17 00:00:00 2001 From: npm Date: Thu, 13 Oct 2016 11:10:03 -0700 Subject: Clean up fx_basic_util a little - Nit fixes. - Remove unused methods. - Replace FX_BOOL with bool. Review-Url: https://codereview.chromium.org/2419433004 --- core/fxcrt/fx_basic_util.cpp | 153 +++++++++++-------------------------------- core/fxcrt/fx_stream.h | 47 +++++++++---- 2 files changed, 75 insertions(+), 125 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index ae3959bdb9..df22d4bf24 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -7,13 +7,6 @@ #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_ext.h" -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ -#include -#include -#else -#include -#endif - #include #include #include @@ -85,6 +78,7 @@ static const FX_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); } @@ -107,16 +101,14 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { cc++; } while (cc < len) { - if (strc[cc] != '+' && strc[cc] != '-') { + if (strc[cc] != '+' && strc[cc] != '-') break; - } cc++; } FX_FLOAT value = 0; while (cc < len) { - if (strc[cc] == '.') { + if (strc[cc] == '.') break; - } value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); cc++; } @@ -145,36 +137,15 @@ void FXSYS_snprintf(char* str, FXSYS_vsnprintf(str, size, fmt, ap); va_end(ap); } + void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap) { (void)_vsnprintf(str, size, fmt, ap); - if (size) { + if (size) str[size - 1] = 0; - } } #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -class CFindFileData { - public: - virtual ~CFindFileData() {} - HANDLE m_Handle; - FX_BOOL m_bEnd; -}; - -class CFindFileDataA : public CFindFileData { - public: - ~CFindFileDataA() override {} - WIN32_FIND_DATAA m_FindData; -}; - -class CFindFileDataW : public CFindFileData { - public: - ~CFindFileDataW() override {} - WIN32_FIND_DATAW m_FindData; -}; -#endif - -void* FX_OpenFolder(const FX_CHAR* path) { +FX_FileHandle* FX_OpenFolder(const FX_CHAR* path) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ std::unique_ptr pData(new CFindFileDataA); pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), @@ -183,101 +154,54 @@ void* FX_OpenFolder(const FX_CHAR* path) { if (pData->m_Handle == INVALID_HANDLE_VALUE) return nullptr; - pData->m_bEnd = FALSE; + pData->m_bEnd = false; return pData.release(); #else - DIR* dir = opendir(path); - return dir; + return opendir(path); #endif } -void* FX_OpenFolder(const FX_WCHAR* path) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - std::unique_ptr pData(new CFindFileDataW); - pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), - FindExInfoStandard, &pData->m_FindData, - FindExSearchNameMatch, nullptr, 0); - if (pData->m_Handle == INVALID_HANDLE_VALUE) - return nullptr; +bool FX_GetNextFile(FX_FileHandle* handle, + CFX_ByteString* filename, + bool* bFolder) { + if (!handle) + return false; - pData->m_bEnd = FALSE; - return pData.release(); -#else - DIR* dir = opendir(CFX_ByteString::FromUnicode(path).c_str()); - return dir; -#endif -} -FX_BOOL FX_GetNextFile(void* handle, - CFX_ByteString& filename, - FX_BOOL& bFolder) { - if (!handle) { - return FALSE; - } #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - CFindFileDataA* pData = (CFindFileDataA*)handle; - if (pData->m_bEnd) - return FALSE; - - filename = pData->m_FindData.cFileName; - bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) - pData->m_bEnd = TRUE; - return TRUE; -#elif defined(__native_client__) - abort(); - return FALSE; -#else - struct dirent* de = readdir((DIR*)handle); - if (!de) { - return FALSE; - } - filename = de->d_name; - bFolder = de->d_type == DT_DIR; - return TRUE; -#endif -} -FX_BOOL FX_GetNextFile(void* handle, - CFX_WideString& filename, - FX_BOOL& bFolder) { - if (!handle) { - return FALSE; - } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - CFindFileDataW* pData = (CFindFileDataW*)handle; - if (pData->m_bEnd) { - return FALSE; - } - filename = pData->m_FindData.cFileName; - bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { - pData->m_bEnd = TRUE; - } - return TRUE; + if (handle->m_bEnd) + return false; + + *filename = handle->m_FindData.cFileName; + *bFolder = + (handle->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + if (!FindNextFileA(handle->m_Handle, &handle->m_FindData)) + handle->m_bEnd = true; + return true; #elif defined(__native_client__) abort(); - return FALSE; + return false; #else - struct dirent* de = readdir((DIR*)handle); - if (!de) { - return FALSE; - } - filename = CFX_WideString::FromLocal(de->d_name); - bFolder = de->d_type == DT_DIR; - return TRUE; + struct dirent* de = readdir(handle); + if (!de) + return false; + *filename = de->d_name; + *bFolder = de->d_type == DT_DIR; + return true; #endif } -void FX_CloseFolder(void* handle) { - if (!handle) { + +void FX_CloseFolder(FX_FileHandle* handle) { + if (!handle) return; - } + #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - CFindFileData* pData = (CFindFileData*)handle; - FindClose(pData->m_Handle); - delete pData; + FindClose(handle->m_Handle); + delete handle; #else - closedir((DIR*)handle); + closedir(handle); #endif } + FX_WCHAR FX_GetFolderSeparator() { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ return '\\'; @@ -330,7 +254,8 @@ uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) { bitMask = (1 << std::min(bitOffset, nbits)) - 1; dstShift = nbits - bitOffset; } - uint32_t result = (uint32_t)(*dataPtr++ >> bitShift & bitMask) << dstShift; + uint32_t result = + static_cast((*dataPtr++ >> bitShift & bitMask) << dstShift); while (dstShift >= 8) { dstShift -= 8; result |= *dataPtr++ << dstShift; diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h index 5a5a650650..047fedf9bb 100644 --- a/core/fxcrt/fx_stream.h +++ b/core/fxcrt/fx_stream.h @@ -10,22 +10,18 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -void* FX_OpenFolder(const FX_CHAR* path); -void* FX_OpenFolder(const FX_WCHAR* path); -FX_BOOL FX_GetNextFile(void* handle, - CFX_ByteString& filename, - FX_BOOL& bFolder); -FX_BOOL FX_GetNextFile(void* handle, - CFX_WideString& filename, - FX_BOOL& bFolder); -void FX_CloseFolder(void* handle); -FX_WCHAR FX_GetFolderSeparator(); - #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +#include + +class CFindFileDataA; + +typedef CFindFileDataA FX_FileHandle; #define FX_FILESIZE int32_t #else +#include #include #include +#include #include #ifndef O_BINARY @@ -36,9 +32,17 @@ FX_WCHAR FX_GetFolderSeparator(); #define O_LARGEFILE 0 #endif // O_LARGEFILE +typedef DIR FX_FileHandle; #define FX_FILESIZE off_t #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +FX_FileHandle* FX_OpenFolder(const FX_CHAR* path); +bool FX_GetNextFile(FX_FileHandle* handle, + CFX_ByteString* filename, + bool* bFolder); +void FX_CloseFolder(FX_FileHandle* handle); +FX_WCHAR FX_GetFolderSeparator(); + #define FX_GETBYTEOFFSET32(a) 0 #define FX_GETBYTEOFFSET40(a) 0 #define FX_GETBYTEOFFSET48(a) 0 @@ -159,4 +163,25 @@ class IFX_BufferRead : public IFX_StreamRead { virtual FX_FILESIZE GetBlockOffset() = 0; }; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +class CFindFileData { + public: + virtual ~CFindFileData() {} + HANDLE m_Handle; + bool m_bEnd; +}; + +class CFindFileDataA : public CFindFileData { + public: + ~CFindFileDataA() override {} + WIN32_FIND_DATAA m_FindData; +}; + +class CFindFileDataW : public CFindFileData { + public: + ~CFindFileDataW() override {} + WIN32_FIND_DATAW m_FindData; +}; +#endif + #endif // CORE_FXCRT_FX_STREAM_H_ -- cgit v1.2.3