summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/fx_basic_util.cpp')
-rw-r--r--core/fxcrt/fx_basic_util.cpp153
1 files changed, 39 insertions, 114 deletions
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 <dirent.h>
-#include <sys/types.h>
-#else
-#include <direct.h>
-#endif
-
#include <algorithm>
#include <cctype>
#include <limits>
@@ -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<CFindFileDataA> 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<CFindFileDataW> 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<uint32_t>((*dataPtr++ >> bitShift & bitMask) << dstShift);
while (dstShift >= 8) {
dstShift -= 8;
result |= *dataPtr++ << dstShift;