| OLD | NEW |
| 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 #include "core/fxcrt/include/fx_basic.h" | 7 #include "core/fxcrt/include/fx_basic.h" |
| 8 #include "core/fxcrt/include/fx_ext.h" | 8 #include "core/fxcrt/include/fx_ext.h" |
| 9 | 9 |
| 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 11 #include <dirent.h> | 11 #include <dirent.h> |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #else | 13 #else |
| 14 #include <direct.h> | 14 #include <direct.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include <algorithm> | 17 #include <algorithm> |
| 18 #include <cctype> | 18 #include <cctype> |
| 19 #include <memory> | 19 #include <memory> |
| 20 | 20 |
| 21 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { | 21 bool FX_atonum(const CFX_ByteStringC& strc, void* pData) { |
| 22 if (strc.Find('.') == -1) { | 22 if (strc.Find('.') != -1) { |
| 23 bInteger = TRUE; | 23 FX_FLOAT* pFloat = static_cast<FX_FLOAT*>(pData); |
| 24 int cc = 0; | 24 *pFloat = FX_atof(strc); |
| 25 pdfium::base::CheckedNumeric<int> integer = 0; | 25 return false; |
| 26 FX_STRSIZE len = strc.GetLength(); | |
| 27 bool bNegative = false; | |
| 28 if (strc[0] == '+') { | |
| 29 cc++; | |
| 30 } else if (strc[0] == '-') { | |
| 31 bNegative = true; | |
| 32 cc++; | |
| 33 } | |
| 34 while (cc < len && std::isdigit(strc[cc])) { | |
| 35 integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); | |
| 36 if (!integer.IsValid()) | |
| 37 break; | |
| 38 cc++; | |
| 39 } | |
| 40 if (bNegative) { | |
| 41 integer = -integer; | |
| 42 } | |
| 43 *(int*)pData = integer.ValueOrDefault(0); | |
| 44 } else { | |
| 45 bInteger = FALSE; | |
| 46 *(FX_FLOAT*)pData = FX_atof(strc); | |
| 47 } | 26 } |
| 27 |
| 28 int cc = 0; |
| 29 pdfium::base::CheckedNumeric<int> integer = 0; |
| 30 bool bNegative = false; |
| 31 if (strc[0] == '+') { |
| 32 cc++; |
| 33 } else if (strc[0] == '-') { |
| 34 bNegative = true; |
| 35 cc++; |
| 36 } |
| 37 while (cc < strc.GetLength() && std::isdigit(strc[cc])) { |
| 38 integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); |
| 39 if (!integer.IsValid()) |
| 40 break; |
| 41 cc++; |
| 42 } |
| 43 if (bNegative) |
| 44 integer = -integer; |
| 45 |
| 46 int* pInt = static_cast<int*>(pData); |
| 47 *pInt = integer.ValueOrDefault(0); |
| 48 return true; |
| 48 } | 49 } |
| 49 | 50 |
| 50 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { | 51 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { |
| 51 if (strc.IsEmpty()) | 52 if (strc.IsEmpty()) |
| 52 return 0.0; | 53 return 0.0; |
| 53 | 54 |
| 54 int cc = 0; | 55 int cc = 0; |
| 55 bool bNegative = false; | 56 bool bNegative = false; |
| 56 int len = strc.GetLength(); | 57 int len = strc.GetLength(); |
| 57 if (strc[0] == '+') { | 58 if (strc[0] == '+') { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 dstShift -= 8; | 293 dstShift -= 8; |
| 293 result |= *dataPtr++ << dstShift; | 294 result |= *dataPtr++ << dstShift; |
| 294 } | 295 } |
| 295 if (dstShift > 0) { | 296 if (dstShift > 0) { |
| 296 bitShift = 8 - dstShift; | 297 bitShift = 8 - dstShift; |
| 297 bitMask = (1 << dstShift) - 1; | 298 bitMask = (1 << dstShift) - 1; |
| 298 result |= *dataPtr++ >> bitShift & bitMask; | 299 result |= *dataPtr++ >> bitShift & bitMask; |
| 299 } | 300 } |
| 300 return result; | 301 return result; |
| 301 } | 302 } |
| OLD | NEW |