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

Side by Side Diff: core/src/fxcrt/fx_basic_wstring.cpp

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

Powered by Google App Engine
This is Rietveld 408576698