| 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 <stddef.h> // For offsetof(). | 7 #include <stddef.h> // For offsetof(). |
| 8 #include <cctype> | |
| 9 | 8 |
| 10 #include "../../include/fxcrt/fx_basic.h" | 9 #include "../../include/fxcrt/fx_basic.h" |
| 11 #include "../../include/fxcrt/fx_ext.h" | |
| 12 #include "../../../third_party/base/numerics/safe_math.h" | 10 #include "../../../third_party/base/numerics/safe_math.h" |
| 13 | 11 |
| 14 // static | 12 // static |
| 15 CFX_WideString::StringData* CFX_WideString::StringData::Create(int nLen) { | 13 CFX_WideString::StringData* CFX_WideString::StringData::Create(int nLen) { |
| 16 // TODO(palmer): |nLen| should really be declared as |size_t|, or | 14 // TODO(palmer): |nLen| should really be declared as |size_t|, or |
| 17 // at least unsigned. | 15 // at least unsigned. |
| 18 if (nLen == 0 || nLen < 0) { | 16 if (nLen == 0 || nLen < 0) { |
| 19 return NULL; | 17 return NULL; |
| 20 } | 18 } |
| 21 | 19 |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 } else if (*lpsz == '*') { | 758 } else if (*lpsz == '*') { |
| 761 nWidth = va_arg(argList, int); | 759 nWidth = va_arg(argList, int); |
| 762 } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ') | 760 } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ') |
| 763 ; | 761 ; |
| 764 else { | 762 else { |
| 765 break; | 763 break; |
| 766 } | 764 } |
| 767 } | 765 } |
| 768 if (nWidth == 0) { | 766 if (nWidth == 0) { |
| 769 nWidth = FXSYS_wtoi(lpsz); | 767 nWidth = FXSYS_wtoi(lpsz); |
| 770 while (std::isdigit(*lpsz)) | 768 for (; *lpsz != 0 && (*lpsz) <= '9' && (*lpsz) >= '0'; lpsz++) |
| 771 ++lpsz; | 769 ; |
| 772 } | 770 } |
| 773 if (nWidth < 0 || nWidth > 128 * 1024) { | 771 if (nWidth < 0 || nWidth > 128 * 1024) { |
| 774 lpszFormat = L"Bad width"; | 772 lpszFormat = L"Bad width"; |
| 775 nMaxLen = 10; | 773 nMaxLen = 10; |
| 776 break; | 774 break; |
| 777 } | 775 } |
| 778 int nPrecision = 0; | 776 int nPrecision = 0; |
| 779 if (*lpsz == '.') { | 777 if (*lpsz == '.') { |
| 780 lpsz++; | 778 lpsz++; |
| 781 if (*lpsz == '*') { | 779 if (*lpsz == '*') { |
| 782 nPrecision = va_arg(argList, int); | 780 nPrecision = va_arg(argList, int); |
| 783 lpsz++; | 781 lpsz++; |
| 784 } else { | 782 } else { |
| 785 nPrecision = FXSYS_wtoi(lpsz); | 783 nPrecision = FXSYS_wtoi(lpsz); |
| 786 while (std::isdigit(*lpsz)) | 784 for (; *lpsz != 0 && (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) |
| 787 ++lpsz; | 785 ; |
| 788 } | 786 } |
| 789 } | 787 } |
| 790 if (nPrecision < 0 || nPrecision > 128 * 1024) { | 788 if (nPrecision < 0 || nPrecision > 128 * 1024) { |
| 791 lpszFormat = L"Bad precision"; | 789 lpszFormat = L"Bad precision"; |
| 792 nMaxLen = 14; | 790 nMaxLen = 14; |
| 793 break; | 791 break; |
| 794 } | 792 } |
| 795 int nModifier = 0; | 793 int nModifier = 0; |
| 796 if (*lpsz == L'I' && *(lpsz + 1) == L'6' && *(lpsz + 2) == L'4') { | 794 if (*lpsz == L'I' && *(lpsz + 1) == L'6' && *(lpsz + 2) == L'4') { |
| 797 lpsz += 3; | 795 lpsz += 3; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 cc++; | 961 cc++; |
| 964 } else if (str[0] == '-') { | 962 } else if (str[0] == '-') { |
| 965 bNegative = TRUE; | 963 bNegative = TRUE; |
| 966 cc++; | 964 cc++; |
| 967 } | 965 } |
| 968 int integer = 0; | 966 int integer = 0; |
| 969 while (cc < len) { | 967 while (cc < len) { |
| 970 if (str[cc] == '.') { | 968 if (str[cc] == '.') { |
| 971 break; | 969 break; |
| 972 } | 970 } |
| 973 integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]); | 971 integer = integer * 10 + str[cc] - '0'; |
| 974 cc++; | 972 cc++; |
| 975 } | 973 } |
| 976 FX_FLOAT fraction = 0; | 974 FX_FLOAT fraction = 0; |
| 977 if (str[cc] == '.') { | 975 if (str[cc] == '.') { |
| 978 cc++; | 976 cc++; |
| 979 FX_FLOAT scale = 0.1f; | 977 FX_FLOAT scale = 0.1f; |
| 980 while (cc < len) { | 978 while (cc < len) { |
| 981 fraction += scale * FXSYS_toDecimalDigit(str[cc]); | 979 fraction += scale * (str[cc] - '0'); |
| 982 scale *= 0.1f; | 980 scale *= 0.1f; |
| 983 cc++; | 981 cc++; |
| 984 } | 982 } |
| 985 } | 983 } |
| 986 fraction += (FX_FLOAT)integer; | 984 fraction += (FX_FLOAT)integer; |
| 987 return bNegative ? -fraction : fraction; | 985 return bNegative ? -fraction : fraction; |
| 988 } | 986 } |
| 989 int CFX_WideString::GetInteger() const { | 987 int CFX_WideString::GetInteger() const { |
| 990 if (m_pData == NULL) { | 988 if (m_pData == NULL) { |
| 991 return 0; | 989 return 0; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 return (CFX_CharMap*)&g_DefaultJISMapper; | 1057 return (CFX_CharMap*)&g_DefaultJISMapper; |
| 1060 case 936: | 1058 case 936: |
| 1061 return (CFX_CharMap*)&g_DefaultGBKMapper; | 1059 return (CFX_CharMap*)&g_DefaultGBKMapper; |
| 1062 case 949: | 1060 case 949: |
| 1063 return (CFX_CharMap*)&g_DefaultUHCMapper; | 1061 return (CFX_CharMap*)&g_DefaultUHCMapper; |
| 1064 case 950: | 1062 case 950: |
| 1065 return (CFX_CharMap*)&g_DefaultBig5Mapper; | 1063 return (CFX_CharMap*)&g_DefaultBig5Mapper; |
| 1066 } | 1064 } |
| 1067 return NULL; | 1065 return NULL; |
| 1068 } | 1066 } |
| OLD | NEW |