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

Side by Side Diff: core/src/fxcrt/fx_basic_util.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « core/src/fxcrt/fx_basic_maps.cpp ('k') | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/fxcrt/fx_basic.h" 7 #include "../../include/fxcrt/fx_basic.h"
8 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 8 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <dirent.h> 10 #include <dirent.h>
11 #else 11 #else
12 #include <direct.h> 12 #include <direct.h>
13 #endif 13 #endif
14 CFX_PrivateData::~CFX_PrivateData() 14 CFX_PrivateData::~CFX_PrivateData()
15 { 15 {
16 ClearAll(); 16 ClearAll();
17 } 17 }
18 void FX_PRIVATEDATA::FreeData() 18 void FX_PRIVATEDATA::FreeData()
19 { 19 {
20 if (m_pData == NULL) { 20 if (m_pData == NULL) {
21 return; 21 return;
22 } 22 }
23 if (m_bSelfDestruct) { 23 if (m_bSelfDestruct) {
24 delete (CFX_DestructObject*)m_pData; 24 delete (CFX_DestructObject*)m_pData;
25 } else if (m_pCallback) { 25 } else if (m_pCallback) {
26 m_pCallback(m_pData); 26 m_pCallback(m_pData);
27 } 27 }
28 } 28 }
29 void CFX_PrivateData::AddData(void* pModuleId, void* pData, PD_CALLBACK_FREEDATA callback, FX_BOOL bSelfDestruct) 29 void CFX_PrivateData::AddData(void* pModuleId, void* pData, PD_CALLBACK_FREEDATA callback, bool bSelfDestruct)
30 { 30 {
31 if (pModuleId == NULL) { 31 if (pModuleId == NULL) {
32 return; 32 return;
33 } 33 }
34 FX_PRIVATEDATA* pList = m_DataList.GetData(); 34 FX_PRIVATEDATA* pList = m_DataList.GetData();
35 int count = m_DataList.GetSize(); 35 int count = m_DataList.GetSize();
36 for (int i = 0; i < count; i ++) { 36 for (int i = 0; i < count; i ++) {
37 if (pList[i].m_pModuleId == pModuleId) { 37 if (pList[i].m_pModuleId == pModuleId) {
38 pList[i].FreeData(); 38 pList[i].FreeData();
39 pList[i].m_pData = pData; 39 pList[i].m_pData = pData;
40 pList[i].m_pCallback = callback; 40 pList[i].m_pCallback = callback;
41 return; 41 return;
42 } 42 }
43 } 43 }
44 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct}; 44 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct};
45 m_DataList.Add(data); 45 m_DataList.Add(data);
46 } 46 }
47 void CFX_PrivateData::SetPrivateData(void* pModuleId, void* pData, PD_CALLBACK_F REEDATA callback) 47 void CFX_PrivateData::SetPrivateData(void* pModuleId, void* pData, PD_CALLBACK_F REEDATA callback)
48 { 48 {
49 AddData(pModuleId, pData, callback, FALSE); 49 AddData(pModuleId, pData, callback, false);
50 } 50 }
51 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) 51 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj)
52 { 52 {
53 AddData(pModuleId, pObj, NULL, TRUE); 53 AddData(pModuleId, pObj, NULL, true);
54 } 54 }
55 FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) 55 bool CFX_PrivateData::RemovePrivateData(void* pModuleId)
56 { 56 {
57 if (pModuleId == NULL) { 57 if (pModuleId == NULL) {
58 return FALSE; 58 return false;
59 } 59 }
60 FX_PRIVATEDATA* pList = m_DataList.GetData(); 60 FX_PRIVATEDATA* pList = m_DataList.GetData();
61 int count = m_DataList.GetSize(); 61 int count = m_DataList.GetSize();
62 for (int i = 0; i < count; i ++) { 62 for (int i = 0; i < count; i ++) {
63 if (pList[i].m_pModuleId == pModuleId) { 63 if (pList[i].m_pModuleId == pModuleId) {
64 m_DataList.RemoveAt(i); 64 m_DataList.RemoveAt(i);
65 return TRUE; 65 return true;
66 } 66 }
67 } 67 }
68 return FALSE; 68 return false;
69 } 69 }
70 void* CFX_PrivateData::GetPrivateData(void* pModuleId) 70 void* CFX_PrivateData::GetPrivateData(void* pModuleId)
71 { 71 {
72 if (pModuleId == NULL) { 72 if (pModuleId == NULL) {
73 return NULL; 73 return NULL;
74 } 74 }
75 FX_PRIVATEDATA* pList = m_DataList.GetData(); 75 FX_PRIVATEDATA* pList = m_DataList.GetData();
76 int count = m_DataList.GetSize(); 76 int count = m_DataList.GetSize();
77 for (int i = 0; i < count; i ++) { 77 for (int i = 0; i < count; i ++) {
78 if (pList[i].m_pModuleId == pModuleId) { 78 if (pList[i].m_pModuleId == pModuleId) {
79 return pList[i].m_pData; 79 return pList[i].m_pData;
80 } 80 }
81 } 81 }
82 return NULL; 82 return NULL;
83 } 83 }
84 void CFX_PrivateData::ClearAll() 84 void CFX_PrivateData::ClearAll()
85 { 85 {
86 FX_PRIVATEDATA* pList = m_DataList.GetData(); 86 FX_PRIVATEDATA* pList = m_DataList.GetData();
87 int count = m_DataList.GetSize(); 87 int count = m_DataList.GetSize();
88 for (int i = 0; i < count; i ++) { 88 for (int i = 0; i < count; i ++) {
89 pList[i].FreeData(); 89 pList[i].FreeData();
90 } 90 }
91 m_DataList.RemoveAll(); 91 m_DataList.RemoveAll();
92 } 92 }
93 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) 93 void FX_atonum(const CFX_ByteStringC& strc, bool& bInteger, void* pData)
94 { 94 {
95 if (FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength()) == NULL) { 95 if (FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength()) == NULL) {
96 bInteger = TRUE; 96 bInteger = true;
97 int cc = 0, integer = 0; 97 int cc = 0, integer = 0;
98 const FX_CHAR* str = strc.GetCStr(); 98 const FX_CHAR* str = strc.GetCStr();
99 int len = strc.GetLength(); 99 int len = strc.GetLength();
100 FX_BOOL bNegative = FALSE; 100 bool bNegative = false;
101 if (str[0] == '+') { 101 if (str[0] == '+') {
102 cc++; 102 cc++;
103 } else if (str[0] == '-') { 103 } else if (str[0] == '-') {
104 bNegative = TRUE; 104 bNegative = true;
105 cc++; 105 cc++;
106 } 106 }
107 while (cc < len) { 107 while (cc < len) {
108 if (str[cc] < '0' || str[cc] > '9') { 108 if (str[cc] < '0' || str[cc] > '9') {
109 break; 109 break;
110 } 110 }
111 integer = integer * 10 + str[cc] - '0'; 111 integer = integer * 10 + str[cc] - '0';
112 if (integer < 0) { 112 if (integer < 0) {
113 break; 113 break;
114 } 114 }
115 cc ++; 115 cc ++;
116 } 116 }
117 if (bNegative) { 117 if (bNegative) {
118 integer = -integer; 118 integer = -integer;
119 } 119 }
120 *(int*)pData = integer; 120 *(int*)pData = integer;
121 } else { 121 } else {
122 bInteger = FALSE; 122 bInteger = false;
123 *(FX_FLOAT*)pData = FX_atof(strc); 123 *(FX_FLOAT*)pData = FX_atof(strc);
124 } 124 }
125 } 125 }
126 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) 126 FX_FLOAT FX_atof(const CFX_ByteStringC& strc)
127 { 127 {
128 if (strc.GetLength() == 0) { 128 if (strc.GetLength() == 0) {
129 return 0.0; 129 return 0.0;
130 } 130 }
131 int cc = 0; 131 int cc = 0;
132 FX_BOOL bNegative = FALSE; 132 bool bNegative = false;
133 const FX_CHAR* str = strc.GetCStr(); 133 const FX_CHAR* str = strc.GetCStr();
134 int len = strc.GetLength(); 134 int len = strc.GetLength();
135 if (str[0] == '+') { 135 if (str[0] == '+') {
136 cc++; 136 cc++;
137 } else if (str[0] == '-') { 137 } else if (str[0] == '-') {
138 bNegative = TRUE; 138 bNegative = true;
139 cc++; 139 cc++;
140 } 140 }
141 while (cc < len) { 141 while (cc < len) {
142 if (str[cc] != '+' && str[cc] != '-') { 142 if (str[cc] != '+' && str[cc] != '-') {
143 break; 143 break;
144 } 144 }
145 cc ++; 145 cc ++;
146 } 146 }
147 FX_FLOAT value = 0; 147 FX_FLOAT value = 0;
148 while (cc < len) { 148 while (cc < len) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 void FXSYS_vsnprintf(char *str, size_t size, const char* fmt, va_list ap) 181 void FXSYS_vsnprintf(char *str, size_t size, const char* fmt, va_list ap)
182 { 182 {
183 (void) _vsnprintf(str, size, fmt, ap); 183 (void) _vsnprintf(str, size, fmt, ap);
184 if (size) { 184 if (size) {
185 str[size - 1] = 0; 185 str[size - 1] = 0;
186 } 186 }
187 } 187 }
188 #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 188 #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900
189 189
190 static FX_BOOL FX_IsDigit(uint8_t ch) 190 static bool FX_IsDigit(uint8_t ch)
191 { 191 {
192 return (ch >= '0' && ch <= '9') ? TRUE : FALSE; 192 return (ch >= '0' && ch <= '9') ? true : false;
193 } 193 }
194 static FX_BOOL FX_IsXDigit(uint8_t ch) 194 static bool FX_IsXDigit(uint8_t ch)
195 { 195 {
196 return (FX_IsDigit(ch) || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f ')) ? TRUE : FALSE; 196 return (FX_IsDigit(ch) || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f ')) ? true : false;
197 } 197 }
198 static uint8_t FX_MakeUpper(uint8_t ch) 198 static uint8_t FX_MakeUpper(uint8_t ch)
199 { 199 {
200 if (ch < 'a' || ch > 'z') { 200 if (ch < 'a' || ch > 'z') {
201 return ch; 201 return ch;
202 } 202 }
203 return ch - 32; 203 return ch - 32;
204 } 204 }
205 static int FX_HexToI(uint8_t ch) 205 static int FX_HexToI(uint8_t ch)
206 { 206 {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 292 }
293 } 293 }
294 return CFX_WideString::FromUTF8(rURI, rURI.GetLength()); 294 return CFX_WideString::FromUTF8(rURI, rURI.GetLength());
295 } 295 }
296 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 296 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
297 class CFindFileData 297 class CFindFileData
298 { 298 {
299 public: 299 public:
300 virtual ~CFindFileData() {} 300 virtual ~CFindFileData() {}
301 HANDLE m_Handle; 301 HANDLE m_Handle;
302 FX_BOOL» » » » m_bEnd; 302 bool» » » » m_bEnd;
303 }; 303 };
304 class CFindFileDataA : public CFindFileData 304 class CFindFileDataA : public CFindFileData
305 { 305 {
306 public: 306 public:
307 virtual ~CFindFileDataA() {} 307 virtual ~CFindFileDataA() {}
308 WIN32_FIND_DATAA m_FindData; 308 WIN32_FIND_DATAA m_FindData;
309 }; 309 };
310 class CFindFileDataW : public CFindFileData 310 class CFindFileDataW : public CFindFileData
311 { 311 {
312 public: 312 public:
(...skipping 12 matching lines...) Expand all
325 pData->m_Handle = FindFirstFileExA(CFX_ByteString(path) + "/*.*", FindExInfo Standard, &pData->m_FindData, FindExSearchNameMatch, NULL, 0); 325 pData->m_Handle = FindFirstFileExA(CFX_ByteString(path) + "/*.*", FindExInfo Standard, &pData->m_FindData, FindExSearchNameMatch, NULL, 0);
326 #endif 326 #endif
327 #else 327 #else
328 CFindFileDataW* pData = new CFindFileDataW; 328 CFindFileDataW* pData = new CFindFileDataW;
329 pData->m_Handle = FindFirstFileW(CFX_WideString::FromLocal(path) + L"/*.*", &pData->m_FindData); 329 pData->m_Handle = FindFirstFileW(CFX_WideString::FromLocal(path) + L"/*.*", &pData->m_FindData);
330 #endif 330 #endif
331 if (pData->m_Handle == INVALID_HANDLE_VALUE) { 331 if (pData->m_Handle == INVALID_HANDLE_VALUE) {
332 delete pData; 332 delete pData;
333 return NULL; 333 return NULL;
334 } 334 }
335 pData->m_bEnd = FALSE; 335 pData->m_bEnd = false;
336 return pData; 336 return pData;
337 #else 337 #else
338 DIR* dir = opendir(path); 338 DIR* dir = opendir(path);
339 return dir; 339 return dir;
340 #endif 340 #endif
341 } 341 }
342 void* FX_OpenFolder(const FX_WCHAR* path) 342 void* FX_OpenFolder(const FX_WCHAR* path)
343 { 343 {
344 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 344 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
345 CFindFileDataW* pData = new CFindFileDataW; 345 CFindFileDataW* pData = new CFindFileDataW;
346 #ifdef _FX_WINAPI_PARTITION_DESKTOP_ 346 #ifdef _FX_WINAPI_PARTITION_DESKTOP_
347 pData->m_Handle = FindFirstFileW((CFX_WideString(path) + L"/*.*").c_str(), & pData->m_FindData); 347 pData->m_Handle = FindFirstFileW((CFX_WideString(path) + L"/*.*").c_str(), & pData->m_FindData);
348 #else 348 #else
349 pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), FindExInfoStandard, &pData->m_FindData, FindExSearchNameMatch, NULL, 0); 349 pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), FindExInfoStandard, &pData->m_FindData, FindExSearchNameMatch, NULL, 0);
350 #endif 350 #endif
351 if (pData->m_Handle == INVALID_HANDLE_VALUE) { 351 if (pData->m_Handle == INVALID_HANDLE_VALUE) {
352 delete pData; 352 delete pData;
353 return NULL; 353 return NULL;
354 } 354 }
355 pData->m_bEnd = FALSE; 355 pData->m_bEnd = false;
356 return pData; 356 return pData;
357 #else 357 #else
358 DIR* dir = opendir(CFX_ByteString::FromUnicode(path)); 358 DIR* dir = opendir(CFX_ByteString::FromUnicode(path));
359 return dir; 359 return dir;
360 #endif 360 #endif
361 } 361 }
362 FX_BOOL FX_GetNextFile(void* handle, CFX_ByteString& filename, FX_BOOL& bFolder) 362 bool FX_GetNextFile(void* handle, CFX_ByteString& filename, bool& bFolder)
363 { 363 {
364 if (handle == NULL) { 364 if (handle == NULL) {
365 return FALSE; 365 return false;
366 } 366 }
367 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 367 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
368 #ifndef _WIN32_WCE 368 #ifndef _WIN32_WCE
369 CFindFileDataA* pData = (CFindFileDataA*)handle; 369 CFindFileDataA* pData = (CFindFileDataA*)handle;
370 if (pData->m_bEnd) { 370 if (pData->m_bEnd) {
371 return FALSE; 371 return false;
372 } 372 }
373 filename = pData->m_FindData.cFileName; 373 filename = pData->m_FindData.cFileName;
374 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; 374 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
375 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) { 375 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) {
376 pData->m_bEnd = TRUE; 376 pData->m_bEnd = true;
377 } 377 }
378 return TRUE; 378 return true;
379 #else 379 #else
380 CFindFileDataW* pData = (CFindFileDataW*)handle; 380 CFindFileDataW* pData = (CFindFileDataW*)handle;
381 if (pData->m_bEnd) { 381 if (pData->m_bEnd) {
382 return FALSE; 382 return false;
383 } 383 }
384 filename = CFX_ByteString::FromUnicode(pData->m_FindData.cFileName); 384 filename = CFX_ByteString::FromUnicode(pData->m_FindData.cFileName);
385 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; 385 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
386 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { 386 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) {
387 pData->m_bEnd = TRUE; 387 pData->m_bEnd = true;
388 } 388 }
389 return TRUE; 389 return true;
390 #endif 390 #endif
391 #elif defined(__native_client__) 391 #elif defined(__native_client__)
392 abort(); 392 abort();
393 return FALSE; 393 return false;
394 #else 394 #else
395 struct dirent *de = readdir((DIR*)handle); 395 struct dirent *de = readdir((DIR*)handle);
396 if (de == NULL) { 396 if (de == NULL) {
397 return FALSE; 397 return false;
398 } 398 }
399 filename = de->d_name; 399 filename = de->d_name;
400 bFolder = de->d_type == DT_DIR; 400 bFolder = de->d_type == DT_DIR;
401 return TRUE; 401 return true;
402 #endif 402 #endif
403 } 403 }
404 FX_BOOL FX_GetNextFile(void* handle, CFX_WideString& filename, FX_BOOL& bFolder) 404 bool FX_GetNextFile(void* handle, CFX_WideString& filename, bool& bFolder)
405 { 405 {
406 if (handle == NULL) { 406 if (handle == NULL) {
407 return FALSE; 407 return false;
408 } 408 }
409 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 409 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
410 CFindFileDataW* pData = (CFindFileDataW*)handle; 410 CFindFileDataW* pData = (CFindFileDataW*)handle;
411 if (pData->m_bEnd) { 411 if (pData->m_bEnd) {
412 return FALSE; 412 return false;
413 } 413 }
414 filename = pData->m_FindData.cFileName; 414 filename = pData->m_FindData.cFileName;
415 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; 415 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
416 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { 416 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) {
417 pData->m_bEnd = TRUE; 417 pData->m_bEnd = true;
418 } 418 }
419 return TRUE; 419 return true;
420 #elif defined(__native_client__) 420 #elif defined(__native_client__)
421 abort(); 421 abort();
422 return FALSE; 422 return false;
423 #else 423 #else
424 struct dirent *de = readdir((DIR*)handle); 424 struct dirent *de = readdir((DIR*)handle);
425 if (de == NULL) { 425 if (de == NULL) {
426 return FALSE; 426 return false;
427 } 427 }
428 filename = CFX_WideString::FromLocal(de->d_name); 428 filename = CFX_WideString::FromLocal(de->d_name);
429 bFolder = de->d_type == DT_DIR; 429 bFolder = de->d_type == DT_DIR;
430 return TRUE; 430 return true;
431 #endif 431 #endif
432 } 432 }
433 void FX_CloseFolder(void* handle) 433 void FX_CloseFolder(void* handle)
434 { 434 {
435 if (handle == NULL) { 435 if (handle == NULL) {
436 return; 436 return;
437 } 437 }
438 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 438 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
439 CFindFileData* pData = (CFindFileData*)handle; 439 CFindFileData* pData = (CFindFileData*)handle;
440 FindClose(pData->m_Handle); 440 FindClose(pData->m_Handle);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 487 }
488 488
489 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1 &v) 489 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1 &v)
490 { 490 {
491 return CFX_Vector_3by1( 491 return CFX_Vector_3by1(
492 a * v.a + b * v.b + c * v.c, 492 a * v.a + b * v.b + c * v.c,
493 d * v.a + e * v.b + f * v.c, 493 d * v.a + e * v.b + f * v.c,
494 g * v.a + h * v.b + i * v.c 494 g * v.a + h * v.b + i * v.c
495 ); 495 );
496 } 496 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_maps.cpp ('k') | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698