OLD | NEW |
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 <cctype> |
| 11 #include <cwctype> |
| 12 |
10 #include "fx_system.h" | 13 #include "fx_system.h" |
11 | 14 |
12 #ifdef __cplusplus | |
13 extern "C" { | |
14 #endif | |
15 | |
16 FX_FLOAT FXSYS_tan(FX_FLOAT a); | 15 FX_FLOAT FXSYS_tan(FX_FLOAT a); |
17 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); | 16 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); |
18 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, | 17 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, |
19 int32_t iLength = -1, | 18 int32_t iLength = -1, |
20 int32_t* pUsedLen = NULL); | 19 int32_t* pUsedLen = NULL); |
21 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, | 20 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, |
22 int32_t iLength = -1, | 21 int32_t iLength = -1, |
23 int32_t* pUsedLen = NULL); | 22 int32_t* pUsedLen = NULL); |
24 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); | 23 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); |
25 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); | 24 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); |
26 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); | 25 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); |
27 | 26 |
28 inline FX_BOOL FXSYS_islower(int32_t ch) { | 27 inline FX_BOOL FXSYS_islower(int32_t ch) { |
29 return ch >= 'a' && ch <= 'z'; | 28 return ch >= 'a' && ch <= 'z'; |
30 } | 29 } |
31 inline FX_BOOL FXSYS_isupper(int32_t ch) { | 30 inline FX_BOOL FXSYS_isupper(int32_t ch) { |
32 return ch >= 'A' && ch <= 'Z'; | 31 return ch >= 'A' && ch <= 'Z'; |
33 } | 32 } |
34 inline int32_t FXSYS_tolower(int32_t ch) { | 33 inline int32_t FXSYS_tolower(int32_t ch) { |
35 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); | 34 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); |
36 } | 35 } |
37 inline int32_t FXSYS_toupper(int32_t ch) { | 36 inline int32_t FXSYS_toupper(int32_t ch) { |
38 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); | 37 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); |
39 } | 38 } |
40 | 39 |
| 40 inline int FXSYS_toHexDigit(const FX_CHAR c) { |
| 41 if (!std::isxdigit(c)) |
| 42 return 0; |
| 43 char upchar = std::toupper(c); |
| 44 return upchar > '9' ? upchar - 'A' + 10 : upchar - '0'; |
| 45 } |
| 46 |
| 47 inline int FXSYS_toDecimalDigit(const FX_CHAR c) { |
| 48 if (!std::isdigit(c)) |
| 49 return 0; |
| 50 return c - '0'; |
| 51 } |
| 52 |
| 53 inline int FXSYS_toDecimalDigitWide(const FX_WCHAR c) { |
| 54 if (!std::iswdigit(c)) |
| 55 return 0; |
| 56 return c - L'0'; |
| 57 } |
| 58 |
41 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, | 59 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, |
42 int32_t iLength, | 60 int32_t iLength, |
43 FX_BOOL bIgnoreCase = FALSE); | 61 FX_BOOL bIgnoreCase = FALSE); |
44 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, | 62 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, |
45 int32_t iLength, | 63 int32_t iLength, |
46 FX_BOOL bIgnoreCase = FALSE); | 64 FX_BOOL bIgnoreCase = FALSE); |
47 | 65 |
48 #ifdef __cplusplus | |
49 } | |
50 #endif | |
51 #ifdef __cplusplus | |
52 extern "C" { | |
53 #endif | |
54 | |
55 void* FX_Random_MT_Start(FX_DWORD dwSeed); | 66 void* FX_Random_MT_Start(FX_DWORD dwSeed); |
56 | 67 |
57 FX_DWORD FX_Random_MT_Generate(void* pContext); | 68 FX_DWORD FX_Random_MT_Generate(void* pContext); |
58 | 69 |
59 void FX_Random_MT_Close(void* pContext); | 70 void FX_Random_MT_Close(void* pContext); |
60 | 71 |
61 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); | 72 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); |
62 | 73 |
63 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); | 74 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); |
64 | 75 |
65 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); | 76 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); |
66 #ifdef __cplusplus | 77 |
67 } | |
68 #endif | |
69 template <class baseType> | 78 template <class baseType> |
70 class CFX_SSortTemplate { | 79 class CFX_SSortTemplate { |
71 public: | 80 public: |
72 void ShellSort(baseType* pArray, int32_t iCount) { | 81 void ShellSort(baseType* pArray, int32_t iCount) { |
73 FXSYS_assert(pArray != NULL && iCount > 0); | 82 FXSYS_assert(pArray != NULL && iCount > 0); |
74 int32_t i, j, gap; | 83 int32_t i, j, gap; |
75 baseType v1, v2; | 84 baseType v1, v2; |
76 gap = iCount >> 1; | 85 gap = iCount >> 1; |
77 while (gap > 0) { | 86 while (gap > 0) { |
78 for (i = gap; i < iCount; i++) { | 87 for (i = gap; i < iCount; i++) { |
79 j = i - gap; | 88 j = i - gap; |
80 v1 = pArray[i]; | 89 v1 = pArray[i]; |
81 while (j > -1 && (v2 = pArray[j]) > v1) { | 90 while (j > -1 && (v2 = pArray[j]) > v1) { |
82 pArray[j + gap] = v2; | 91 pArray[j + gap] = v2; |
83 j -= gap; | 92 j -= gap; |
84 } | 93 } |
85 pArray[j + gap] = v1; | 94 pArray[j + gap] = v1; |
86 } | 95 } |
87 gap >>= 1; | 96 gap >>= 1; |
88 } | 97 } |
89 } | 98 } |
90 }; | 99 }; |
91 | 100 |
92 #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_ | 101 #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_ |
OLD | NEW |