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