John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | 95e854f | 2015-06-13 00:58:06 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | cfb1944 | 2017-04-20 13:13:04 -0400 | [diff] [blame] | 7 | #ifndef CORE_FXCRT_FX_EXTENSION_H_ |
| 8 | #define CORE_FXCRT_FX_EXTENSION_H_ |
Tom Sepez | 0570b8a | 2015-04-06 13:49:25 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | 10cfea1 | 2015-11-16 13:09:00 -0500 | [diff] [blame] | 10 | #include <cctype> |
| 11 | #include <cwctype> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 12 | #include <memory> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
Dan Sinclair | bcd1e70 | 2017-08-31 13:19:18 -0400 | [diff] [blame^] | 14 | #include "core/fxcrt/fx_string.h" |
Tom Sepez | 7386e29 | 2015-11-20 09:35:06 -0800 | [diff] [blame] | 15 | |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 16 | #define FX_INVALID_OFFSET static_cast<uint32_t>(-1) |
| 17 | |
Dan Sinclair | bcd1e70 | 2017-08-31 13:19:18 -0400 | [diff] [blame^] | 18 | #ifdef PDF_ENABLE_XFA |
| 19 | #define FX_IsOdd(a) ((a)&1) |
| 20 | #endif // PDF_ENABLE_XFA |
| 21 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 22 | float FXSYS_wcstof(const wchar_t* pwsStr, |
| 23 | int32_t iLength = -1, |
| 24 | int32_t* pUsedLen = nullptr); |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 25 | wchar_t* FXSYS_wcsncpy(wchar_t* dstStr, const wchar_t* srcStr, size_t count); |
| 26 | int32_t FXSYS_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t count); |
Tom Sepez | 0570b8a | 2015-04-06 13:49:25 -0700 | [diff] [blame] | 27 | |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 28 | inline bool FXSYS_islower(int32_t ch) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | return ch >= 'a' && ch <= 'z'; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | } |
Dan Sinclair | 72c6b18 | 2017-04-03 13:39:26 -0400 | [diff] [blame] | 31 | |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 32 | inline bool FXSYS_isupper(int32_t ch) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | return ch >= 'A' && ch <= 'Z'; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | } |
Dan Sinclair | 72c6b18 | 2017-04-03 13:39:26 -0400 | [diff] [blame] | 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | inline int32_t FXSYS_tolower(int32_t ch) { |
| 37 | return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | } |
Dan Sinclair | 72c6b18 | 2017-04-03 13:39:26 -0400 | [diff] [blame] | 39 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | inline int32_t FXSYS_toupper(int32_t ch) { |
| 41 | return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | } |
Dan Sinclair | 72c6b18 | 2017-04-03 13:39:26 -0400 | [diff] [blame] | 43 | |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 44 | inline bool FXSYS_iswalpha(wchar_t wch) { |
Lei Zhang | ef002c8 | 2017-04-24 16:28:07 -0700 | [diff] [blame] | 45 | return FXSYS_isupper(wch) || FXSYS_islower(wch); |
Wei Li | 60eac0f | 2015-12-17 18:16:23 -0800 | [diff] [blame] | 46 | } |
Dan Sinclair | 72c6b18 | 2017-04-03 13:39:26 -0400 | [diff] [blame] | 47 | |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 48 | inline bool FXSYS_iswalnum(wchar_t wch) { |
Lei Zhang | e247ec4 | 2017-04-20 21:41:36 -0700 | [diff] [blame] | 49 | return FXSYS_iswalpha(wch) || std::iswdigit(wch); |
Wei Li | 60eac0f | 2015-12-17 18:16:23 -0800 | [diff] [blame] | 50 | } |
Dan Sinclair | 72c6b18 | 2017-04-03 13:39:26 -0400 | [diff] [blame] | 51 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 52 | inline bool FXSYS_iswspace(wchar_t c) { |
dsinclair | ce56557 | 2016-06-23 14:00:32 -0700 | [diff] [blame] | 53 | return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); |
| 54 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | |
Nicolas Pena | ecd3646 | 2017-04-18 13:12:41 -0400 | [diff] [blame] | 56 | inline bool FXSYS_isHexDigit(const char c) { |
| 57 | return !((c & 0x80) || !std::isxdigit(c)); |
| 58 | } |
| 59 | |
Lei Zhang | e8c1d41 | 2017-05-04 12:13:55 -0700 | [diff] [blame] | 60 | inline int FXSYS_HexCharToInt(const char c) { |
Nicolas Pena | ecd3646 | 2017-04-18 13:12:41 -0400 | [diff] [blame] | 61 | if (!FXSYS_isHexDigit(c)) |
Dan Sinclair | 10cfea1 | 2015-11-16 13:09:00 -0500 | [diff] [blame] | 62 | return 0; |
| 63 | char upchar = std::toupper(c); |
| 64 | return upchar > '9' ? upchar - 'A' + 10 : upchar - '0'; |
| 65 | } |
| 66 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 67 | inline bool FXSYS_isDecimalDigit(const char c) { |
Nicolas Pena | ecd3646 | 2017-04-18 13:12:41 -0400 | [diff] [blame] | 68 | return !((c & 0x80) || !std::isdigit(c)); |
Dan Sinclair | 1c91537 | 2016-03-03 17:12:58 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 71 | inline bool FXSYS_isDecimalDigit(const wchar_t c) { |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 72 | return !!std::iswdigit(c); |
Dan Sinclair | 1c91537 | 2016-03-03 17:12:58 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Lei Zhang | e8c1d41 | 2017-05-04 12:13:55 -0700 | [diff] [blame] | 75 | inline int FXSYS_DecimalCharToInt(const char c) { |
Nicolas Pena | ecd3646 | 2017-04-18 13:12:41 -0400 | [diff] [blame] | 76 | return FXSYS_isDecimalDigit(c) ? c - '0' : 0; |
Dan Sinclair | 10cfea1 | 2015-11-16 13:09:00 -0500 | [diff] [blame] | 77 | } |
| 78 | |
Lei Zhang | e8c1d41 | 2017-05-04 12:13:55 -0700 | [diff] [blame] | 79 | inline int FXSYS_DecimalCharToInt(const wchar_t c) { |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 80 | return std::iswdigit(c) ? c - L'0' : 0; |
Dan Sinclair | 10cfea1 | 2015-11-16 13:09:00 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Nicolas Pena | 54b9166 | 2017-05-05 16:49:30 -0400 | [diff] [blame] | 83 | void FXSYS_IntToTwoHexChars(uint8_t c, char* buf); |
| 84 | |
| 85 | void FXSYS_IntToFourHexChars(uint16_t c, char* buf); |
| 86 | |
| 87 | size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf); |
| 88 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 89 | float FXSYS_FractionalScale(size_t scale_factor, int value); |
dsinclair | ce56557 | 2016-06-23 14:00:32 -0700 | [diff] [blame] | 90 | int FXSYS_FractionalScaleCount(); |
| 91 | |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 92 | void* FX_Random_MT_Start(uint32_t dwSeed); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | void FX_Random_MT_Close(void* pContext); |
tsepez | d987143 | 2016-09-15 14:01:31 -0700 | [diff] [blame] | 94 | uint32_t FX_Random_MT_Generate(void* pContext); |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 95 | void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount); |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 96 | void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 97 | |
Tom Sepez | 5c4c193 | 2015-11-25 12:15:38 -0800 | [diff] [blame] | 98 | #ifdef PDF_ENABLE_XFA |
tsepez | 3128d1c | 2017-01-10 06:03:26 -0800 | [diff] [blame] | 99 | struct FX_GUID { |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 100 | uint32_t data1; |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 101 | uint16_t data2; |
| 102 | uint16_t data3; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | uint8_t data4[8]; |
tsepez | 3128d1c | 2017-01-10 06:03:26 -0800 | [diff] [blame] | 104 | }; |
| 105 | void FX_GUID_CreateV4(FX_GUID* pGUID); |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 106 | CFX_ByteString FX_GUID_ToString(const FX_GUID* pGUID, bool bSeparator = true); |
Tom Sepez | a2c42ce | 2015-11-25 15:52:28 -0800 | [diff] [blame] | 107 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 10cfea1 | 2015-11-16 13:09:00 -0500 | [diff] [blame] | 108 | |
Dan Sinclair | bcd1e70 | 2017-08-31 13:19:18 -0400 | [diff] [blame^] | 109 | uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); |
| 110 | |
Dan Sinclair | cfb1944 | 2017-04-20 13:13:04 -0400 | [diff] [blame] | 111 | #endif // CORE_FXCRT_FX_EXTENSION_H_ |