1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_ 8 #define CORE_INCLUDE_FXCRT_FX_EXT_H_ 9 10 #include <cctype> 11 #include <cwctype> 12 13 #include "core/include/fxcrt/fx_basic.h" 14 15 FX_FLOAT FXSYS_tan(FX_FLOAT a); 16 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); 17 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, 18 int32_t iLength = -1, 19 int32_t* pUsedLen = NULL); 20 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, 21 int32_t iLength = -1, 22 int32_t* pUsedLen = NULL); 23 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); 24 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); 25 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); 26 27 inline FX_BOOL FXSYS_islower(int32_t ch) { 28 return ch >= 'a' && ch <= 'z'; 29 } 30 inline FX_BOOL FXSYS_isupper(int32_t ch) { 31 return ch >= 'A' && ch <= 'Z'; 32 } 33 inline int32_t FXSYS_tolower(int32_t ch) { 34 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); 35 } 36 inline int32_t FXSYS_toupper(int32_t ch) { 37 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); 38 } 39 inline FX_BOOL FXSYS_iswalpha(wchar_t wch) { 40 return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z'); 41 } 42 inline FX_BOOL FXSYS_iswdigit(wchar_t wch) { 43 return wch >= L'0' && wch <= L'9'; 44 } 45 inline FX_BOOL FXSYS_iswalnum(wchar_t wch) { 46 return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch); 47 } 48 49 inline int FXSYS_toHexDigit(const FX_CHAR c) { 50 if (!std::isxdigit(c)) 51 return 0; 52 char upchar = std::toupper(c); 53 return upchar > '9' ? upchar - 'A' + 10 : upchar - '0'; 54 } 55 56 inline int FXSYS_toDecimalDigit(const FX_CHAR c) { 57 if (!std::isdigit(c)) 58 return 0; 59 return c - '0'; 60 } 61 62 inline int FXSYS_toDecimalDigitWide(const FX_WCHAR c) { 63 if (!std::iswdigit(c)) 64 return 0; 65 return c - L'0'; 66 } 67 68 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, 69 int32_t iLength, 70 FX_BOOL bIgnoreCase = FALSE); 71 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, 72 int32_t iLength, 73 FX_BOOL bIgnoreCase = FALSE); 74 75 void* FX_Random_MT_Start(FX_DWORD dwSeed); 76 77 FX_DWORD FX_Random_MT_Generate(void* pContext); 78 79 void FX_Random_MT_Close(void* pContext); 80 81 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); 82 83 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); 84 85 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); 86 87 #ifdef PDF_ENABLE_XFA 88 typedef struct FX_GUID { 89 FX_DWORD data1; 90 FX_WORD data2; 91 FX_WORD data3; 92 uint8_t data4[8]; 93 } FX_GUID, *FX_LPGUID; 94 typedef FX_GUID const* FX_LPCGUID; 95 void FX_GUID_CreateV4(FX_LPGUID pGUID); 96 void FX_GUID_ToString(FX_LPCGUID pGUID, 97 CFX_ByteString& bsStr, 98 FX_BOOL bSeparator = TRUE); 99 #endif // PDF_ENABLE_XFA 100 101 template <class baseType> 102 class CFX_SSortTemplate { 103 public: 104 void ShellSort(baseType* pArray, int32_t iCount) { 105 FXSYS_assert(pArray && iCount > 0); 106 int32_t i, j, gap; 107 baseType v1, v2; 108 gap = iCount >> 1; 109 while (gap > 0) { 110 for (i = gap; i < iCount; i++) { 111 j = i - gap; 112 v1 = pArray[i]; 113 while (j > -1 && (v2 = pArray[j]) > v1) { 114 pArray[j + gap] = v2; 115 j -= gap; 116 } 117 pArray[j + gap] = v1; 118 } 119 gap >>= 1; 120 } 121 } 122 }; 123 124 #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_ 125