summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
authornpm <npm@chromium.org>2016-10-13 11:10:03 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-13 11:10:03 -0700
commitaeb44f8c4675141e170329d5093b251fbfad8023 (patch)
tree5aa3077a0f03695cbac969588a51756e1bc85a4e /core/fxcrt
parenta4060a324d606d5a8e1d2a16d3b55a6d14a0ddbf (diff)
downloadpdfium-aeb44f8c4675141e170329d5093b251fbfad8023.tar.xz
Clean up fx_basic_util a little
- Nit fixes. - Remove unused methods. - Replace FX_BOOL with bool. Review-Url: https://codereview.chromium.org/2419433004
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/fx_basic_util.cpp153
-rw-r--r--core/fxcrt/fx_stream.h47
2 files changed, 75 insertions, 125 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;
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 <direct.h>
+
+class CFindFileDataA;
+
+typedef CFindFileDataA FX_FileHandle;
#define FX_FILESIZE int32_t
#else
+#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
#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_