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 15FX_FLOAT FXSYS_tan(FX_FLOAT a); 16FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); 17FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, 18 int32_t iLength = -1, 19 int32_t* pUsedLen = NULL); 20FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, 21 int32_t iLength = -1, 22 int32_t* pUsedLen = NULL); 23FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); 24int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); 25int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); 26 27inline FX_BOOL FXSYS_islower(int32_t ch) { 28 return ch >= 'a' && ch <= 'z'; 29} 30inline FX_BOOL FXSYS_isupper(int32_t ch) { 31 return ch >= 'A' && ch <= 'Z'; 32} 33inline int32_t FXSYS_tolower(int32_t ch) { 34 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); 35} 36inline int32_t FXSYS_toupper(int32_t ch) { 37 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); 38} 39inline FX_BOOL FXSYS_iswalpha(wchar_t wch) { 40 return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z'); 41} 42inline FX_BOOL FXSYS_iswdigit(wchar_t wch) { 43 return wch >= L'0' && wch <= L'9'; 44} 45inline FX_BOOL FXSYS_iswalnum(wchar_t wch) { 46 return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch); 47} 48 49inline 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 56inline int FXSYS_toDecimalDigit(const FX_CHAR c) { 57 if (!std::isdigit(c)) 58 return 0; 59 return c - '0'; 60} 61 62inline int FXSYS_toDecimalDigitWide(const FX_WCHAR c) { 63 if (!std::iswdigit(c)) 64 return 0; 65 return c - L'0'; 66} 67 68FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, 69 int32_t iLength, 70 FX_BOOL bIgnoreCase = FALSE); 71FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, 72 int32_t iLength, 73 FX_BOOL bIgnoreCase = FALSE); 74 75void* FX_Random_MT_Start(FX_DWORD dwSeed); 76 77FX_DWORD FX_Random_MT_Generate(void* pContext); 78 79void FX_Random_MT_Close(void* pContext); 80 81void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); 82 83void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); 84 85void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); 86 87#ifdef PDF_ENABLE_XFA 88typedef 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; 94typedef FX_GUID const* FX_LPCGUID; 95void FX_GUID_CreateV4(FX_LPGUID pGUID); 96void FX_GUID_ToString(FX_LPCGUID pGUID, 97 CFX_ByteString& bsStr, 98 FX_BOOL bSeparator = TRUE); 99#endif // PDF_ENABLE_XFA 100 101template <class baseType> 102class 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