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

Unified Diff: core/fxcrt/fx_basic_util.cpp

Issue 2419433004: Clean up fx_basic_util a little (Closed)
Patch Set: Another method deletion Created 4 years, 2 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 | « no previous file | core/fxcrt/fx_stream.h » ('j') | core/fxcrt/fx_stream.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_basic_util.cpp
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index ae3959bdb98003efb9e7eb6897af96bd8e8f5dc2..549fdaa00b7c98a94ef0f1ba279ecaf40d2cf10d 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -85,6 +85,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 +108,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,11 +144,11 @@ 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
@@ -158,7 +157,7 @@ class CFindFileData {
public:
virtual ~CFindFileData() {}
HANDLE m_Handle;
- FX_BOOL m_bEnd;
+ bool m_bEnd;
};
class CFindFileDataA : public CFindFileData {
@@ -183,7 +182,7 @@ 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);
@@ -191,85 +190,38 @@ void* FX_OpenFolder(const FX_CHAR* 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(void* 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_
dsinclair 2016/10/12 20:43:23 Can we duplicate the method signature inside the #
npm 2016/10/12 22:13:19 Cleaner: created typedef for file handle.
CFindFileDataA* pData = (CFindFileDataA*)handle;
if (pData->m_bEnd)
- return FALSE;
+ return false;
filename = pData->m_FindData.cFileName;
- bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+ bFolder =
+ (pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
if (!FindNextFileA(pData->m_Handle, &pData->m_FindData))
- pData->m_bEnd = TRUE;
- return TRUE;
+ pData->m_bEnd = true;
+ return true;
#elif defined(__native_client__)
dsinclair 2016/10/12 20:43:23 Do we even support building under __native_client_
npm 2016/10/12 22:13:19 Deleted... Tom?
abort();
- return FALSE;
+ return false;
#else
struct dirent* de = readdir((DIR*)handle);
- if (!de) {
- return FALSE;
- }
+ 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;
-#elif defined(__native_client__)
- abort();
- 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;
+ return true;
#endif
}
+
void FX_CloseFolder(void* handle) {
- if (!handle) {
+ if (!handle)
return;
- }
+
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
CFindFileData* pData = (CFindFileData*)handle;
FindClose(pData->m_Handle);
@@ -278,6 +230,7 @@ void FX_CloseFolder(void* handle) {
closedir((DIR*)handle);
#endif
}
+
FX_WCHAR FX_GetFolderSeparator() {
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
return '\\';
@@ -330,7 +283,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;
« no previous file with comments | « no previous file | core/fxcrt/fx_stream.h » ('j') | core/fxcrt/fx_stream.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698