Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: core/include/fxcrt/fx_ext.h

Issue 1431683008: Revert "Revert "Revert "Cleanup some numeric code.""" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | core/src/fpdfapi/fpdf_font/fpdf_font.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_ 7 #ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_
8 #define CORE_INCLUDE_FXCRT_FX_EXT_H_ 8 #define CORE_INCLUDE_FXCRT_FX_EXT_H_
9 9
10 #include <cctype> 10 #include "fx_system.h"
11 11
12 #include "fx_system.h" 12 #ifdef __cplusplus
13 extern "C" {
14 #endif
13 15
14 FX_FLOAT FXSYS_tan(FX_FLOAT a); 16 FX_FLOAT FXSYS_tan(FX_FLOAT a);
15 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); 17 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
16 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, 18 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
17 int32_t iLength = -1, 19 int32_t iLength = -1,
18 int32_t* pUsedLen = NULL); 20 int32_t* pUsedLen = NULL);
19 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, 21 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr,
20 int32_t iLength = -1, 22 int32_t iLength = -1,
21 int32_t* pUsedLen = NULL); 23 int32_t* pUsedLen = NULL);
22 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); 24 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count);
23 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); 25 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count);
24 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); 26 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count);
25 27
26 inline FX_BOOL FXSYS_islower(int32_t ch) { 28 inline FX_BOOL FXSYS_islower(int32_t ch) {
27 return ch >= 'a' && ch <= 'z'; 29 return ch >= 'a' && ch <= 'z';
28 } 30 }
29 inline FX_BOOL FXSYS_isupper(int32_t ch) { 31 inline FX_BOOL FXSYS_isupper(int32_t ch) {
30 return ch >= 'A' && ch <= 'Z'; 32 return ch >= 'A' && ch <= 'Z';
31 } 33 }
32 inline int32_t FXSYS_tolower(int32_t ch) { 34 inline int32_t FXSYS_tolower(int32_t ch) {
33 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); 35 return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20);
34 } 36 }
35 inline int32_t FXSYS_toupper(int32_t ch) { 37 inline int32_t FXSYS_toupper(int32_t ch) {
36 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); 38 return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
37 } 39 }
38 40
39 inline int FXSYS_toHexDigit(char c) {
40 if (!std::isxdigit(c))
41 return 0;
42 char upchar = std::toupper(c);
43 return upchar > '9' ? upchar - 'A' + 10 : upchar - '0';
44 }
45
46 inline int FXSYS_toDecimalDigit(char c) {
47 if (!std::isdigit(c))
48 return 0;
49 return c - '0';
50 }
51
52 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, 41 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr,
53 int32_t iLength, 42 int32_t iLength,
54 FX_BOOL bIgnoreCase = FALSE); 43 FX_BOOL bIgnoreCase = FALSE);
55 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, 44 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
56 int32_t iLength, 45 int32_t iLength,
57 FX_BOOL bIgnoreCase = FALSE); 46 FX_BOOL bIgnoreCase = FALSE);
58 47
48 #ifdef __cplusplus
49 }
50 #endif
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
59 void* FX_Random_MT_Start(FX_DWORD dwSeed); 55 void* FX_Random_MT_Start(FX_DWORD dwSeed);
60 56
61 FX_DWORD FX_Random_MT_Generate(void* pContext); 57 FX_DWORD FX_Random_MT_Generate(void* pContext);
62 58
63 void FX_Random_MT_Close(void* pContext); 59 void FX_Random_MT_Close(void* pContext);
64 60
65 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); 61 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount);
66 62
67 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); 63 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount);
68 64
69 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); 65 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount);
70 66 #ifdef __cplusplus
67 }
68 #endif
71 template <class baseType> 69 template <class baseType>
72 class CFX_SSortTemplate { 70 class CFX_SSortTemplate {
73 public: 71 public:
74 void ShellSort(baseType* pArray, int32_t iCount) { 72 void ShellSort(baseType* pArray, int32_t iCount) {
75 FXSYS_assert(pArray != NULL && iCount > 0); 73 FXSYS_assert(pArray != NULL && iCount > 0);
76 int32_t i, j, gap; 74 int32_t i, j, gap;
77 baseType v1, v2; 75 baseType v1, v2;
78 gap = iCount >> 1; 76 gap = iCount >> 1;
79 while (gap > 0) { 77 while (gap > 0) {
80 for (i = gap; i < iCount; i++) { 78 for (i = gap; i < iCount; i++) {
81 j = i - gap; 79 j = i - gap;
82 v1 = pArray[i]; 80 v1 = pArray[i];
83 while (j > -1 && (v2 = pArray[j]) > v1) { 81 while (j > -1 && (v2 = pArray[j]) > v1) {
84 pArray[j + gap] = v2; 82 pArray[j + gap] = v2;
85 j -= gap; 83 j -= gap;
86 } 84 }
87 pArray[j + gap] = v1; 85 pArray[j + gap] = v1;
88 } 86 }
89 gap >>= 1; 87 gap >>= 1;
90 } 88 }
91 } 89 }
92 }; 90 };
93 91
94 #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_ 92 #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | core/src/fpdfapi/fpdf_font/fpdf_font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698