| OLD | NEW |
| (Empty) |
| 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 #include "xfa/src/fgas/crt/fgas_system.h" | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "core/include/fxcrt/fx_system.h" | |
| 12 | |
| 13 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | |
| 14 _FX_OS_ == _FX_WIN64_ | |
| 15 #include <io.h> | |
| 16 #elif _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_LINUX_Mini_ | |
| 17 #include <sys/times.h> | |
| 18 #endif | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 inline FX_BOOL FX_isupper(int32_t ch) { | |
| 23 return ch >= 'A' && ch <= 'Z'; | |
| 24 } | |
| 25 | |
| 26 inline int32_t FX_tolower(int32_t ch) { | |
| 27 return FX_isupper(ch) ? (ch + 0x20) : ch; | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 int32_t FX_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count) { | |
| 33 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0); | |
| 34 FX_WCHAR wch1 = 0, wch2 = 0; | |
| 35 while (count-- > 0) { | |
| 36 wch1 = (FX_WCHAR)FX_tolower(*s1++); | |
| 37 wch2 = (FX_WCHAR)FX_tolower(*s2++); | |
| 38 if (wch1 != wch2) { | |
| 39 break; | |
| 40 } | |
| 41 } | |
| 42 return wch1 - wch2; | |
| 43 } | |
| 44 | |
| 45 int32_t FX_filelength(FXSYS_FILE* file) { | |
| 46 FXSYS_assert(file != NULL); | |
| 47 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | |
| 48 return _filelength(_fileno(file)); | |
| 49 #else | |
| 50 int32_t iPos = FXSYS_ftell(file); | |
| 51 FXSYS_fseek(file, 0, FXSYS_SEEK_END); | |
| 52 int32_t iLen = FXSYS_ftell(file); | |
| 53 FXSYS_fseek(file, iPos, FXSYS_SEEK_SET); | |
| 54 return iLen; | |
| 55 #endif | |
| 56 } | |
| 57 | |
| 58 FX_BOOL FX_fsetsize(FXSYS_FILE* file, int32_t size) { | |
| 59 FXSYS_assert(file != NULL); | |
| 60 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | |
| 61 return _chsize(_fileno(file), size) == 0; | |
| 62 #elif _FX_OS_ == _FX_WIN32_MOBILE_ | |
| 63 HANDLE hFile = _fileno(file); | |
| 64 FX_DWORD dwPos = ::SetFilePointer(hFile, 0, 0, FILE_CURRENT); | |
| 65 ::SetFilePointer(hFile, size, 0, FILE_BEGIN); | |
| 66 FX_BOOL bRet = ::SetEndOfFile(hFile); | |
| 67 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); | |
| 68 return bRet; | |
| 69 #else | |
| 70 return FALSE; | |
| 71 #endif | |
| 72 } | |
| 73 | |
| 74 FX_FLOAT FX_wcstof(const FX_WCHAR* pwsStr, int32_t iLength, int32_t* pUsedLen) { | |
| 75 FXSYS_assert(pwsStr != NULL); | |
| 76 if (iLength < 0) { | |
| 77 iLength = FXSYS_wcslen(pwsStr); | |
| 78 } | |
| 79 if (iLength == 0) { | |
| 80 return 0.0f; | |
| 81 } | |
| 82 int32_t iUsedLen = 0; | |
| 83 FX_BOOL bNegtive = FALSE; | |
| 84 switch (pwsStr[iUsedLen]) { | |
| 85 case '-': | |
| 86 bNegtive = TRUE; | |
| 87 case '+': | |
| 88 iUsedLen++; | |
| 89 break; | |
| 90 } | |
| 91 FX_FLOAT fValue = 0.0f; | |
| 92 while (iUsedLen < iLength) { | |
| 93 FX_WCHAR wch = pwsStr[iUsedLen]; | |
| 94 if (wch >= L'0' && wch <= L'9') { | |
| 95 fValue = fValue * 10.0f + (wch - L'0'); | |
| 96 } else { | |
| 97 break; | |
| 98 } | |
| 99 iUsedLen++; | |
| 100 } | |
| 101 if (iUsedLen < iLength && pwsStr[iUsedLen] == L'.') { | |
| 102 FX_FLOAT fPrecise = 0.1f; | |
| 103 while (++iUsedLen < iLength) { | |
| 104 FX_WCHAR wch = pwsStr[iUsedLen]; | |
| 105 if (wch >= L'0' && wch <= L'9') { | |
| 106 fValue += (wch - L'0') * fPrecise; | |
| 107 fPrecise *= 0.1f; | |
| 108 } else { | |
| 109 break; | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 if (pUsedLen) { | |
| 114 *pUsedLen = iUsedLen; | |
| 115 } | |
| 116 return bNegtive ? -fValue : fValue; | |
| 117 } | |
| OLD | NEW |