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

Side by Side Diff: core/include/fxcrt/fx_ext.h

Issue 1452673002: Merge to XFA: Reland "Cleanup some numeric code."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month 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
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 #ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_ 7 #ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_
8 #define CORE_INCLUDE_FXCRT_FX_EXT_H_ 8 #define CORE_INCLUDE_FXCRT_FX_EXT_H_
9 9
10 #include "fx_string.h" 10 #include "fx_string.h"
11 #include "fx_system.h" 11 #include "fx_system.h"
12 12
13 #ifdef __cplusplus 13 #include <cctype>
dsinclair 2015/11/16 17:44:48 Merge conflict.
14 extern "C" { 14 #include <cwctype>
15 #endif
16 15
17 FX_FLOAT FXSYS_tan(FX_FLOAT a); 16 FX_FLOAT FXSYS_tan(FX_FLOAT a);
18 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); 17 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
19 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, 18 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
20 int32_t iLength = -1, 19 int32_t iLength = -1,
21 int32_t* pUsedLen = NULL); 20 int32_t* pUsedLen = NULL);
22 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, 21 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr,
23 int32_t iLength = -1, 22 int32_t iLength = -1,
24 int32_t* pUsedLen = NULL); 23 int32_t* pUsedLen = NULL);
25 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); 24 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count);
26 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); 25 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count);
27 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); 26 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count);
28 27
29 inline FX_BOOL FXSYS_islower(int32_t ch) { 28 inline FX_BOOL FXSYS_islower(int32_t ch) {
30 return ch >= 'a' && ch <= 'z'; 29 return ch >= 'a' && ch <= 'z';
31 } 30 }
32 inline FX_BOOL FXSYS_isupper(int32_t ch) { 31 inline FX_BOOL FXSYS_isupper(int32_t ch) {
33 return ch >= 'A' && ch <= 'Z'; 32 return ch >= 'A' && ch <= 'Z';
34 } 33 }
35 inline int32_t FXSYS_tolower(int32_t ch) { 34 inline int32_t FXSYS_tolower(int32_t ch) {
36 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); 35 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20);
37 } 36 }
38 inline int32_t FXSYS_toupper(int32_t ch) { 37 inline int32_t FXSYS_toupper(int32_t ch) {
39 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); 38 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
40 } 39 }
41 40
41 inline int FXSYS_toHexDigit(const FX_CHAR c) {
42 if (!std::isxdigit(c))
43 return 0;
44 char upchar = std::toupper(c);
45 return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
46 }
47
48 inline int FXSYS_toDecimalDigit(const FX_CHAR c) {
49 if (!std::isdigit(c))
50 return 0;
51 return c - '0';
52 }
53
54 inline int FXSYS_toDecimalDigitWide(const FX_WCHAR c) {
55 if (!std::iswdigit(c))
56 return 0;
57 return c - L'0';
58 }
59
42 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, 60 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr,
43 int32_t iLength, 61 int32_t iLength,
44 FX_BOOL bIgnoreCase = FALSE); 62 FX_BOOL bIgnoreCase = FALSE);
45 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, 63 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
46 int32_t iLength, 64 int32_t iLength,
47 FX_BOOL bIgnoreCase = FALSE); 65 FX_BOOL bIgnoreCase = FALSE);
48 66
49 #ifdef __cplusplus
50 }
51 #endif
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 void* FX_Random_MT_Start(FX_DWORD dwSeed); 67 void* FX_Random_MT_Start(FX_DWORD dwSeed);
57 68
58 FX_DWORD FX_Random_MT_Generate(void* pContext); 69 FX_DWORD FX_Random_MT_Generate(void* pContext);
59 70
60 void FX_Random_MT_Close(void* pContext); 71 void FX_Random_MT_Close(void* pContext);
61 72
62 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); 73 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount);
63 74
64 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); 75 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount);
65 76
66 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); 77 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount);
67 #ifdef __cplusplus
dsinclair 2015/11/16 17:44:48 Merge conflict.
68 }
69 #endif
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 78
74 typedef struct FX_GUID { 79 typedef struct FX_GUID {
75 FX_DWORD data1; 80 FX_DWORD data1;
76 FX_WORD data2; 81 FX_WORD data2;
77 FX_WORD data3; 82 FX_WORD data3;
78 uint8_t data4[8]; 83 uint8_t data4[8];
79 } FX_GUID, *FX_LPGUID; 84 } FX_GUID, *FX_LPGUID;
80 typedef FX_GUID const* FX_LPCGUID; 85 typedef FX_GUID const* FX_LPCGUID;
81 86
82 void FX_GUID_CreateV4(FX_LPGUID pGUID); 87 void FX_GUID_CreateV4(FX_LPGUID pGUID);
83 88
84 void FX_GUID_ToString(FX_LPCGUID pGUID, 89 void FX_GUID_ToString(FX_LPCGUID pGUID,
85 CFX_ByteString& bsStr, 90 CFX_ByteString& bsStr,
86 FX_BOOL bSeparator = TRUE); 91 FX_BOOL bSeparator = TRUE);
87 #ifdef __cplusplus 92
dsinclair 2015/11/16 17:44:48 Merge conflict.
88 }
89 #endif
90 template <class baseType> 93 template <class baseType>
91 class CFX_SSortTemplate { 94 class CFX_SSortTemplate {
92 public: 95 public:
93 void ShellSort(baseType* pArray, int32_t iCount) { 96 void ShellSort(baseType* pArray, int32_t iCount) {
94 FXSYS_assert(pArray != NULL && iCount > 0); 97 FXSYS_assert(pArray != NULL && iCount > 0);
95 int32_t i, j, gap; 98 int32_t i, j, gap;
96 baseType v1, v2; 99 baseType v1, v2;
97 gap = iCount >> 1; 100 gap = iCount >> 1;
98 while (gap > 0) { 101 while (gap > 0) {
99 for (i = gap; i < iCount; i++) { 102 for (i = gap; i < iCount; i++) {
100 j = i - gap; 103 j = i - gap;
101 v1 = pArray[i]; 104 v1 = pArray[i];
102 while (j > -1 && (v2 = pArray[j]) > v1) { 105 while (j > -1 && (v2 = pArray[j]) > v1) {
103 pArray[j + gap] = v2; 106 pArray[j + gap] = v2;
104 j -= gap; 107 j -= gap;
105 } 108 }
106 pArray[j + gap] = v1; 109 pArray[j + gap] = v1;
107 } 110 }
108 gap >>= 1; 111 gap >>= 1;
109 } 112 }
110 } 113 }
111 }; 114 };
112 115
113 #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_ 116 #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698