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

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

Issue 1405253007: Revert "Revert "Cleanup some numeric code."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix mac 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
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 "../../include/fxcrt/fx_basic.h" 10 #include "../../include/fxcrt/fx_basic.h"
10 #include "../../../third_party/base/numerics/safe_math.h" 11 #include "../../../third_party/base/numerics/safe_math.h"
11 12
12 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) { 13 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) {
13 if (i == 0) { 14 if (i == 0) {
14 buf[0] = '0'; 15 buf[0] = '0';
15 return 1; 16 return 1;
16 } 17 }
17 char buf1[32]; 18 char buf1[32];
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 ASSERT(dest.m_pData == NULL); 456 ASSERT(dest.m_pData == NULL);
456 dest.m_pData = StringData::Create(nCopyLen); 457 dest.m_pData = StringData::Create(nCopyLen);
457 if (dest.m_pData) { 458 if (dest.m_pData) {
458 FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex, 459 FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex,
459 nCopyLen); 460 nCopyLen);
460 } 461 }
461 } 462 }
462 #define FORCE_ANSI 0x10000 463 #define FORCE_ANSI 0x10000
463 #define FORCE_UNICODE 0x20000 464 #define FORCE_UNICODE 0x20000
464 #define FORCE_INT64 0x40000 465 #define FORCE_INT64 0x40000
465 void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) { 466 void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) {
Tom Sepez 2015/10/29 19:28:31 test, may already have one.
dsinclair 2015/11/03 15:59:02 https://codereview.chromium.org/1411973005/
466 va_list argListSave; 467 va_list argListSave;
467 #if defined(__ARMCC_VERSION) || \ 468 #if defined(__ARMCC_VERSION) || \
468 (!defined(_MSC_VER) && (_FX_CPU_ == _FX_X64_ || _FX_CPU_ == _FX_IA64_ || \ 469 (!defined(_MSC_VER) && (_FX_CPU_ == _FX_X64_ || _FX_CPU_ == _FX_IA64_ || \
469 _FX_CPU_ == _FX_ARM64_)) || \ 470 _FX_CPU_ == _FX_ARM64_)) || \
470 defined(__native_client__) 471 defined(__native_client__)
471 va_copy(argListSave, argList); 472 va_copy(argListSave, argList);
472 #else 473 #else
473 argListSave = argList; 474 argListSave = argList;
474 #endif 475 #endif
475 int nMaxLen = 0; 476 int nMaxLen = 0;
(...skipping 10 matching lines...) Expand all
486 } else if (*lpsz == '*') { 487 } else if (*lpsz == '*') {
487 nWidth = va_arg(argList, int); 488 nWidth = va_arg(argList, int);
488 } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ') 489 } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ')
489 ; 490 ;
490 else { 491 else {
491 break; 492 break;
492 } 493 }
493 } 494 }
494 if (nWidth == 0) { 495 if (nWidth == 0) {
495 nWidth = FXSYS_atoi(lpsz); 496 nWidth = FXSYS_atoi(lpsz);
496 for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) 497 for (; std::isdigit(*lpsz); lpsz++)
497 ; 498 ;
498 } 499 }
499 if (nWidth < 0 || nWidth > 128 * 1024) { 500 if (nWidth < 0 || nWidth > 128 * 1024) {
500 lpszFormat = "Bad width"; 501 lpszFormat = "Bad width";
501 nMaxLen = 10; 502 nMaxLen = 10;
502 break; 503 break;
503 } 504 }
504 int nPrecision = 0; 505 int nPrecision = 0;
505 if (*lpsz == '.') { 506 if (*lpsz == '.') {
506 lpsz++; 507 lpsz++;
507 if (*lpsz == '*') { 508 if (*lpsz == '*') {
508 nPrecision = va_arg(argList, int); 509 nPrecision = va_arg(argList, int);
509 lpsz++; 510 lpsz++;
510 } else { 511 } else {
511 nPrecision = FXSYS_atoi(lpsz); 512 nPrecision = FXSYS_atoi(lpsz);
512 for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++) 513 for (; std::isdigit(*lpsz); lpsz++)
513 ; 514 ;
514 } 515 }
515 } 516 }
516 if (nPrecision < 0 || nPrecision > 128 * 1024) { 517 if (nPrecision < 0 || nPrecision > 128 * 1024) {
517 lpszFormat = "Bad precision"; 518 lpszFormat = "Bad precision";
518 nMaxLen = 14; 519 nMaxLen = 14;
519 break; 520 break;
520 } 521 }
521 int nModifier = 0; 522 int nModifier = 0;
522 if (FXSYS_strncmp(lpsz, "I64", 3) == 0) { 523 if (FXSYS_strncmp(lpsz, "I64", 3) == 0) {
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 fraction %= scale; 1087 fraction %= scale;
1087 scale /= 10; 1088 scale /= 10;
1088 } 1089 }
1089 return buf_size; 1090 return buf_size;
1090 } 1091 }
1091 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { 1092 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) {
1092 FX_CHAR buf[32]; 1093 FX_CHAR buf[32];
1093 FX_STRSIZE len = FX_ftoa(d, buf); 1094 FX_STRSIZE len = FX_ftoa(d, buf);
1094 return CFX_ByteString(buf, len); 1095 return CFX_ByteString(buf, len);
1095 } 1096 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698