blob: f55153c0ad63bcc0f4e445d57e635d01e0aa34bd [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhang95e854f2015-06-13 00:58:06 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclaircfb19442017-04-20 13:13:04 -04007#ifndef CORE_FXCRT_FX_EXTENSION_H_
8#define CORE_FXCRT_FX_EXTENSION_H_
Tom Sepez0570b8a2015-04-06 13:49:25 -07009
Dan Sinclair10cfea12015-11-16 13:09:00 -050010#include <cctype>
11#include <cwctype>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050012#include <memory>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
dsinclaira52ab742016-09-29 13:59:29 -070014#include "core/fxcrt/fx_basic.h"
Tom Sepez7386e292015-11-20 09:35:06 -080015
Wei Li89409932016-03-28 10:33:33 -070016#define FX_INVALID_OFFSET static_cast<uint32_t>(-1)
17
Dan Sinclair05df0752017-03-14 14:43:42 -040018float FXSYS_wcstof(const wchar_t* pwsStr,
19 int32_t iLength = -1,
20 int32_t* pUsedLen = nullptr);
Dan Sinclair812e96c2017-03-13 16:43:37 -040021wchar_t* FXSYS_wcsncpy(wchar_t* dstStr, const wchar_t* srcStr, size_t count);
22int32_t FXSYS_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t count);
Tom Sepez0570b8a2015-04-06 13:49:25 -070023
Wei Li614d20a2016-03-15 13:55:12 -070024inline bool FXSYS_islower(int32_t ch) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025 return ch >= 'a' && ch <= 'z';
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026}
Dan Sinclair72c6b182017-04-03 13:39:26 -040027
Wei Li614d20a2016-03-15 13:55:12 -070028inline bool FXSYS_isupper(int32_t ch) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 return ch >= 'A' && ch <= 'Z';
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030}
Dan Sinclair72c6b182017-04-03 13:39:26 -040031
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032inline int32_t FXSYS_tolower(int32_t ch) {
33 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034}
Dan Sinclair72c6b182017-04-03 13:39:26 -040035
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036inline int32_t FXSYS_toupper(int32_t ch) {
37 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038}
Dan Sinclair72c6b182017-04-03 13:39:26 -040039
Wei Li614d20a2016-03-15 13:55:12 -070040inline bool FXSYS_iswalpha(wchar_t wch) {
Lei Zhangef002c82017-04-24 16:28:07 -070041 return FXSYS_isupper(wch) || FXSYS_islower(wch);
Wei Li60eac0f2015-12-17 18:16:23 -080042}
Dan Sinclair72c6b182017-04-03 13:39:26 -040043
Wei Li614d20a2016-03-15 13:55:12 -070044inline bool FXSYS_iswalnum(wchar_t wch) {
Lei Zhange247ec42017-04-20 21:41:36 -070045 return FXSYS_iswalpha(wch) || std::iswdigit(wch);
Wei Li60eac0f2015-12-17 18:16:23 -080046}
Dan Sinclair72c6b182017-04-03 13:39:26 -040047
Dan Sinclair812e96c2017-03-13 16:43:37 -040048inline bool FXSYS_iswspace(wchar_t c) {
dsinclairce565572016-06-23 14:00:32 -070049 return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09);
50}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Nicolas Penaecd36462017-04-18 13:12:41 -040052inline bool FXSYS_isHexDigit(const char c) {
53 return !((c & 0x80) || !std::isxdigit(c));
54}
55
Lei Zhange8c1d412017-05-04 12:13:55 -070056inline int FXSYS_HexCharToInt(const char c) {
Nicolas Penaecd36462017-04-18 13:12:41 -040057 if (!FXSYS_isHexDigit(c))
Dan Sinclair10cfea12015-11-16 13:09:00 -050058 return 0;
59 char upchar = std::toupper(c);
60 return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
61}
62
Dan Sinclair812e96c2017-03-13 16:43:37 -040063inline bool FXSYS_isDecimalDigit(const char c) {
Nicolas Penaecd36462017-04-18 13:12:41 -040064 return !((c & 0x80) || !std::isdigit(c));
Dan Sinclair1c915372016-03-03 17:12:58 -050065}
66
Dan Sinclair812e96c2017-03-13 16:43:37 -040067inline bool FXSYS_isDecimalDigit(const wchar_t c) {
Wei Li97da9762016-03-11 17:00:48 -080068 return !!std::iswdigit(c);
Dan Sinclair1c915372016-03-03 17:12:58 -050069}
70
Lei Zhange8c1d412017-05-04 12:13:55 -070071inline int FXSYS_DecimalCharToInt(const char c) {
Nicolas Penaecd36462017-04-18 13:12:41 -040072 return FXSYS_isDecimalDigit(c) ? c - '0' : 0;
Dan Sinclair10cfea12015-11-16 13:09:00 -050073}
74
Lei Zhange8c1d412017-05-04 12:13:55 -070075inline int FXSYS_DecimalCharToInt(const wchar_t c) {
Wei Li97da9762016-03-11 17:00:48 -080076 return std::iswdigit(c) ? c - L'0' : 0;
Dan Sinclair10cfea12015-11-16 13:09:00 -050077}
78
Dan Sinclair05df0752017-03-14 14:43:42 -040079float FXSYS_FractionalScale(size_t scale_factor, int value);
dsinclairce565572016-06-23 14:00:32 -070080int FXSYS_FractionalScaleCount();
81
tsepezb5e8f142016-03-25 15:18:35 -070082void* FX_Random_MT_Start(uint32_t dwSeed);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083void FX_Random_MT_Close(void* pContext);
tsepezd9871432016-09-15 14:01:31 -070084uint32_t FX_Random_MT_Generate(void* pContext);
tsepezb5e8f142016-03-25 15:18:35 -070085void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount);
tsepezb5e8f142016-03-25 15:18:35 -070086void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount);
Bo Xufdc00a72014-10-28 23:03:33 -070087
Tom Sepez5c4c1932015-11-25 12:15:38 -080088#ifdef PDF_ENABLE_XFA
tsepez3128d1c2017-01-10 06:03:26 -080089struct FX_GUID {
tsepezb5e8f142016-03-25 15:18:35 -070090 uint32_t data1;
Tom Sepez62a70f92016-03-21 15:00:20 -070091 uint16_t data2;
92 uint16_t data3;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 uint8_t data4[8];
tsepez3128d1c2017-01-10 06:03:26 -080094};
95void FX_GUID_CreateV4(FX_GUID* pGUID);
Tom Sepezec8ff7d2017-04-07 16:58:00 -070096CFX_ByteString FX_GUID_ToString(const FX_GUID* pGUID, bool bSeparator = true);
Tom Sepeza2c42ce2015-11-25 15:52:28 -080097#endif // PDF_ENABLE_XFA
Dan Sinclair10cfea12015-11-16 13:09:00 -050098
Dan Sinclaircfb19442017-04-20 13:13:04 -040099#endif // CORE_FXCRT_FX_EXTENSION_H_