• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FX_EXT_H_
8 #define CORE_FXCRT_FX_EXT_H_
9 
10 #include <cctype>
11 #include <cwctype>
12 #include <memory>
13 
14 #include "core/fxcrt/fx_basic.h"
15 
16 #define FX_INVALID_OFFSET static_cast<uint32_t>(-1)
17 
18 FX_FLOAT FXSYS_tan(FX_FLOAT a);
19 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
20 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
21                       int32_t iLength = -1,
22                       int32_t* pUsedLen = nullptr);
23 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr,
24                       int32_t iLength = -1,
25                       int32_t* pUsedLen = nullptr);
26 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count);
27 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count);
28 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count);
29 
FXSYS_islower(int32_t ch)30 inline bool FXSYS_islower(int32_t ch) {
31   return ch >= 'a' && ch <= 'z';
32 }
FXSYS_isupper(int32_t ch)33 inline bool FXSYS_isupper(int32_t ch) {
34   return ch >= 'A' && ch <= 'Z';
35 }
FXSYS_tolower(int32_t ch)36 inline int32_t FXSYS_tolower(int32_t ch) {
37   return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20);
38 }
FXSYS_toupper(int32_t ch)39 inline int32_t FXSYS_toupper(int32_t ch) {
40   return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
41 }
FXSYS_iswalpha(wchar_t wch)42 inline bool FXSYS_iswalpha(wchar_t wch) {
43   return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z');
44 }
FXSYS_iswdigit(wchar_t wch)45 inline bool FXSYS_iswdigit(wchar_t wch) {
46   return wch >= L'0' && wch <= L'9';
47 }
FXSYS_iswalnum(wchar_t wch)48 inline bool FXSYS_iswalnum(wchar_t wch) {
49   return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch);
50 }
FXSYS_iswspace(FX_WCHAR c)51 inline bool FXSYS_iswspace(FX_WCHAR c) {
52   return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09);
53 }
54 
FXSYS_toHexDigit(const FX_CHAR c)55 inline int FXSYS_toHexDigit(const FX_CHAR c) {
56   if (!std::isxdigit(c))
57     return 0;
58   char upchar = std::toupper(c);
59   return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
60 }
61 
FXSYS_isDecimalDigit(const FX_CHAR c)62 inline bool FXSYS_isDecimalDigit(const FX_CHAR c) {
63   return !!std::isdigit(c);
64 }
65 
FXSYS_isDecimalDigit(const FX_WCHAR c)66 inline bool FXSYS_isDecimalDigit(const FX_WCHAR c) {
67   return !!std::iswdigit(c);
68 }
69 
FXSYS_toDecimalDigit(const FX_CHAR c)70 inline int FXSYS_toDecimalDigit(const FX_CHAR c) {
71   return std::isdigit(c) ? c - '0' : 0;
72 }
73 
FXSYS_toDecimalDigit(const FX_WCHAR c)74 inline int FXSYS_toDecimalDigit(const FX_WCHAR c) {
75   return std::iswdigit(c) ? c - L'0' : 0;
76 }
77 
78 FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value);
79 int FXSYS_FractionalScaleCount();
80 
81 void* FX_Random_MT_Start(uint32_t dwSeed);
82 void FX_Random_MT_Close(void* pContext);
83 uint32_t FX_Random_MT_Generate(void* pContext);
84 void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount);
85 void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount);
86 void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount);
87 
88 #ifdef PDF_ENABLE_XFA
89 struct FX_GUID {
90   uint32_t data1;
91   uint16_t data2;
92   uint16_t data3;
93   uint8_t data4[8];
94 };
95 void FX_GUID_CreateV4(FX_GUID* pGUID);
96 void FX_GUID_ToString(const FX_GUID* pGUID,
97                       CFX_ByteString& bsStr,
98                       bool bSeparator = true);
99 #endif  // PDF_ENABLE_XFA
100 
101 #endif  // CORE_FXCRT_FX_EXT_H_
102