summaryrefslogtreecommitdiff
path: root/core/include/fxcrt/fx_ext.h
blob: a4a92d2fb06a616e7b67d676129ee69580100c01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_
#define CORE_INCLUDE_FXCRT_FX_EXT_H_

#include <cctype>
#include <cwctype>

#include "fx_system.h"

FX_FLOAT FXSYS_tan(FX_FLOAT a);
FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
                      int32_t iLength = -1,
                      int32_t* pUsedLen = NULL);
FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr,
                      int32_t iLength = -1,
                      int32_t* pUsedLen = NULL);
FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count);
int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count);
int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count);

inline FX_BOOL FXSYS_islower(int32_t ch) {
  return ch >= 'a' && ch <= 'z';
}
inline FX_BOOL FXSYS_isupper(int32_t ch) {
  return ch >= 'A' && ch <= 'Z';
}
inline int32_t FXSYS_tolower(int32_t ch) {
  return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20);
}
inline int32_t FXSYS_toupper(int32_t ch) {
  return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
}
inline FX_BOOL FXSYS_iswalpha(wchar_t wch) {
  return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z');
}
inline FX_BOOL FXSYS_iswdigit(wchar_t wch) {
  return wch >= L'0' && wch <= L'9';
}
inline FX_BOOL FXSYS_iswalnum(wchar_t wch) {
  return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch);
}

inline int FXSYS_toHexDigit(const FX_CHAR c) {
  if (!std::isxdigit(c))
    return 0;
  char upchar = std::toupper(c);
  return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
}

inline int FXSYS_toDecimalDigit(const FX_CHAR c) {
  if (!std::isdigit(c))
    return 0;
  return c - '0';
}

inline int FXSYS_toDecimalDigitWide(const FX_WCHAR c) {
  if (!std::iswdigit(c))
    return 0;
  return c - L'0';
}

FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr,
                                 int32_t iLength,
                                 FX_BOOL bIgnoreCase = FALSE);
FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
                                 int32_t iLength,
                                 FX_BOOL bIgnoreCase = FALSE);

void* FX_Random_MT_Start(FX_DWORD dwSeed);

FX_DWORD FX_Random_MT_Generate(void* pContext);

void FX_Random_MT_Close(void* pContext);

void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount);

void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount);

void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount);

template <class baseType>
class CFX_SSortTemplate {
 public:
  void ShellSort(baseType* pArray, int32_t iCount) {
    FXSYS_assert(pArray && iCount > 0);
    int32_t i, j, gap;
    baseType v1, v2;
    gap = iCount >> 1;
    while (gap > 0) {
      for (i = gap; i < iCount; i++) {
        j = i - gap;
        v1 = pArray[i];
        while (j > -1 && (v2 = pArray[j]) > v1) {
          pArray[j + gap] = v2;
          j -= gap;
        }
        pArray[j + gap] = v1;
      }
      gap >>= 1;
    }
  }
};

#endif  // CORE_INCLUDE_FXCRT_FX_EXT_H_