OLD | NEW |
| (Empty) |
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_FXCRT_INCLUDE_FX_EXT_H_ | |
8 #define CORE_FXCRT_INCLUDE_FX_EXT_H_ | |
9 | |
10 #include <cctype> | |
11 #include <cwctype> | |
12 | |
13 #include "core/fxcrt/include/fx_basic.h" | |
14 | |
15 #define FX_INVALID_OFFSET static_cast<uint32_t>(-1) | |
16 | |
17 // TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal. | |
18 // Come up or wait for something better. This appears in this file rather | |
19 // than fx_stream.h due to include ordering restrictions. | |
20 using ScopedFileStream = | |
21 std::unique_ptr<IFX_FileStream, ReleaseDeleter<IFX_FileStream>>; | |
22 | |
23 FX_FLOAT FXSYS_tan(FX_FLOAT a); | |
24 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); | |
25 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, | |
26 int32_t iLength = -1, | |
27 int32_t* pUsedLen = nullptr); | |
28 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, | |
29 int32_t iLength = -1, | |
30 int32_t* pUsedLen = nullptr); | |
31 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); | |
32 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); | |
33 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); | |
34 | |
35 inline bool FXSYS_islower(int32_t ch) { | |
36 return ch >= 'a' && ch <= 'z'; | |
37 } | |
38 inline bool FXSYS_isupper(int32_t ch) { | |
39 return ch >= 'A' && ch <= 'Z'; | |
40 } | |
41 inline int32_t FXSYS_tolower(int32_t ch) { | |
42 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); | |
43 } | |
44 inline int32_t FXSYS_toupper(int32_t ch) { | |
45 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); | |
46 } | |
47 inline bool FXSYS_iswalpha(wchar_t wch) { | |
48 return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z'); | |
49 } | |
50 inline bool FXSYS_iswdigit(wchar_t wch) { | |
51 return wch >= L'0' && wch <= L'9'; | |
52 } | |
53 inline bool FXSYS_iswalnum(wchar_t wch) { | |
54 return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch); | |
55 } | |
56 inline bool FXSYS_iswspace(FX_WCHAR c) { | |
57 return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); | |
58 } | |
59 | |
60 inline int FXSYS_toHexDigit(const FX_CHAR c) { | |
61 if (!std::isxdigit(c)) | |
62 return 0; | |
63 char upchar = std::toupper(c); | |
64 return upchar > '9' ? upchar - 'A' + 10 : upchar - '0'; | |
65 } | |
66 | |
67 inline bool FXSYS_isDecimalDigit(const FX_CHAR c) { | |
68 return !!std::isdigit(c); | |
69 } | |
70 | |
71 inline bool FXSYS_isDecimalDigit(const FX_WCHAR c) { | |
72 return !!std::iswdigit(c); | |
73 } | |
74 | |
75 inline int FXSYS_toDecimalDigit(const FX_CHAR c) { | |
76 return std::isdigit(c) ? c - '0' : 0; | |
77 } | |
78 | |
79 inline int FXSYS_toDecimalDigit(const FX_WCHAR c) { | |
80 return std::iswdigit(c) ? c - L'0' : 0; | |
81 } | |
82 | |
83 FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value); | |
84 int FXSYS_FractionalScaleCount(); | |
85 | |
86 void* FX_Random_MT_Start(uint32_t dwSeed); | |
87 void FX_Random_MT_Close(void* pContext); | |
88 uint32_t FX_Random_MT_Generate(void* pContext); | |
89 void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount); | |
90 void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount); | |
91 void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount); | |
92 | |
93 #ifdef PDF_ENABLE_XFA | |
94 typedef struct FX_GUID { | |
95 uint32_t data1; | |
96 uint16_t data2; | |
97 uint16_t data3; | |
98 uint8_t data4[8]; | |
99 } FX_GUID, *FX_LPGUID; | |
100 typedef FX_GUID const* FX_LPCGUID; | |
101 void FX_GUID_CreateV4(FX_LPGUID pGUID); | |
102 void FX_GUID_ToString(FX_LPCGUID pGUID, | |
103 CFX_ByteString& bsStr, | |
104 FX_BOOL bSeparator = TRUE); | |
105 #endif // PDF_ENABLE_XFA | |
106 | |
107 template <class baseType> | |
108 class CFX_SSortTemplate { | |
109 public: | |
110 void ShellSort(baseType* pArray, int32_t iCount) { | |
111 ASSERT(pArray && iCount > 0); | |
112 int32_t i, j, gap; | |
113 baseType v1, v2; | |
114 gap = iCount >> 1; | |
115 while (gap > 0) { | |
116 for (i = gap; i < iCount; i++) { | |
117 j = i - gap; | |
118 v1 = pArray[i]; | |
119 while (j > -1 && (v2 = pArray[j]) > v1) { | |
120 pArray[j + gap] = v2; | |
121 j -= gap; | |
122 } | |
123 pArray[j + gap] = v1; | |
124 } | |
125 gap >>= 1; | |
126 } | |
127 } | |
128 }; | |
129 | |
130 #endif // CORE_FXCRT_INCLUDE_FX_EXT_H_ | |
OLD | NEW |