| 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 "../../../third_party/base/numerics/safe_math.h" | 10 #include "../../../third_party/base/numerics/safe_math.h" |
| 12 | 11 |
| 13 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) { | 12 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) { |
| 14 if (i == 0) { | 13 if (i == 0) { |
| 15 buf[0] = '0'; | 14 buf[0] = '0'; |
| 16 return 1; | 15 return 1; |
| 17 } | 16 } |
| 18 char buf1[32]; | 17 char buf1[32]; |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } else if (*lpsz == '*') { | 486 } else if (*lpsz == '*') { |
| 488 nWidth = va_arg(argList, int); | 487 nWidth = va_arg(argList, int); |
| 489 } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ') | 488 } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ') |
| 490 ; | 489 ; |
| 491 else { | 490 else { |
| 492 break; | 491 break; |
| 493 } | 492 } |
| 494 } | 493 } |
| 495 if (nWidth == 0) { | 494 if (nWidth == 0) { |
| 496 nWidth = FXSYS_atoi(lpsz); | 495 nWidth = FXSYS_atoi(lpsz); |
| 497 while (std::isdigit(*lpsz)) | 496 for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) |
| 498 lpsz++; | 497 ; |
| 499 } | 498 } |
| 500 if (nWidth < 0 || nWidth > 128 * 1024) { | 499 if (nWidth < 0 || nWidth > 128 * 1024) { |
| 501 lpszFormat = "Bad width"; | 500 lpszFormat = "Bad width"; |
| 502 nMaxLen = 10; | 501 nMaxLen = 10; |
| 503 break; | 502 break; |
| 504 } | 503 } |
| 505 int nPrecision = 0; | 504 int nPrecision = 0; |
| 506 if (*lpsz == '.') { | 505 if (*lpsz == '.') { |
| 507 lpsz++; | 506 lpsz++; |
| 508 if (*lpsz == '*') { | 507 if (*lpsz == '*') { |
| 509 nPrecision = va_arg(argList, int); | 508 nPrecision = va_arg(argList, int); |
| 510 lpsz++; | 509 lpsz++; |
| 511 } else { | 510 } else { |
| 512 nPrecision = FXSYS_atoi(lpsz); | 511 nPrecision = FXSYS_atoi(lpsz); |
| 513 while (std::isdigit(*lpsz)) | 512 for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) |
| 514 lpsz++; | 513 ; |
| 515 } | 514 } |
| 516 } | 515 } |
| 517 if (nPrecision < 0 || nPrecision > 128 * 1024) { | 516 if (nPrecision < 0 || nPrecision > 128 * 1024) { |
| 518 lpszFormat = "Bad precision"; | 517 lpszFormat = "Bad precision"; |
| 519 nMaxLen = 14; | 518 nMaxLen = 14; |
| 520 break; | 519 break; |
| 521 } | 520 } |
| 522 int nModifier = 0; | 521 int nModifier = 0; |
| 523 if (FXSYS_strncmp(lpsz, "I64", 3) == 0) { | 522 if (FXSYS_strncmp(lpsz, "I64", 3) == 0) { |
| 524 lpsz += 3; | 523 lpsz += 3; |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 fraction %= scale; | 1086 fraction %= scale; |
| 1088 scale /= 10; | 1087 scale /= 10; |
| 1089 } | 1088 } |
| 1090 return buf_size; | 1089 return buf_size; |
| 1091 } | 1090 } |
| 1092 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { | 1091 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { |
| 1093 FX_CHAR buf[32]; | 1092 FX_CHAR buf[32]; |
| 1094 FX_STRSIZE len = FX_ftoa(d, buf); | 1093 FX_STRSIZE len = FX_ftoa(d, buf); |
| 1095 return CFX_ByteString(buf, len); | 1094 return CFX_ByteString(buf, len); |
| 1096 } | 1095 } |
| OLD | NEW |