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_EXTENSION_H_ 8 #define CORE_FXCRT_FX_EXTENSION_H_ 9 10 #include <cctype> 11 #include <cwctype> 12 #include <memory> 13 14 #include "core/fxcrt/fx_string.h" 15 16 #define FX_INVALID_OFFSET static_cast<uint32_t>(-1) 17 18 #ifdef PDF_ENABLE_XFA 19 #define FX_IsOdd(a) ((a)&1) 20 #endif // PDF_ENABLE_XFA 21 22 float FXSYS_wcstof(const wchar_t* pwsStr, 23 int32_t iLength = -1, 24 int32_t* pUsedLen = nullptr); 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); 27 28 inline bool FXSYS_islower(int32_t ch) { 29 return ch >= 'a' && ch <= 'z'; 30 } 31 32 inline bool FXSYS_isupper(int32_t ch) { 33 return ch >= 'A' && ch <= 'Z'; 34 } 35 36 inline int32_t FXSYS_tolower(int32_t ch) { 37 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); 38 } 39 40 inline int32_t FXSYS_toupper(int32_t ch) { 41 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); 42 } 43 44 inline bool FXSYS_iswalpha(wchar_t wch) { 45 return FXSYS_isupper(wch) || FXSYS_islower(wch); 46 } 47 48 inline bool FXSYS_iswalnum(wchar_t wch) { 49 return FXSYS_iswalpha(wch) || std::iswdigit(wch); 50 } 51 52 inline bool FXSYS_iswspace(wchar_t c) { 53 return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); 54 } 55 56 inline bool FXSYS_isHexDigit(const char c) { 57 return !((c & 0x80) || !std::isxdigit(c)); 58 } 59 60 inline int FXSYS_HexCharToInt(const char c) { 61 if (!FXSYS_isHexDigit(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 char c) { 68 return !((c & 0x80) || !std::isdigit(c)); 69 } 70 71 inline bool FXSYS_isDecimalDigit(const wchar_t c) { 72 return !!std::iswdigit(c); 73 } 74 75 inline int FXSYS_DecimalCharToInt(const char c) { 76 return FXSYS_isDecimalDigit(c) ? c - '0' : 0; 77 } 78 79 inline int FXSYS_DecimalCharToInt(const wchar_t c) { 80 return std::iswdigit(c) ? c - L'0' : 0; 81 } 82 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 89 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); 90 91 #endif // CORE_FXCRT_FX_EXTENSION_H_ 92