| 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 |
| 9 #include <algorithm> |
| 8 #include <cctype> | 10 #include <cctype> |
| 9 | 11 |
| 10 #include "core/include/fxcrt/fx_basic.h" | 12 #include "core/include/fxcrt/fx_basic.h" |
| 11 #include "core/include/fxcrt/fx_ext.h" | 13 #include "core/include/fxcrt/fx_ext.h" |
| 12 #include "third_party/base/numerics/safe_math.h" | 14 #include "third_party/base/numerics/safe_math.h" |
| 13 | 15 |
| 14 // static | 16 // static |
| 15 CFX_WideString::StringData* CFX_WideString::StringData::Create(int nLen) { | 17 CFX_WideString::StringData* CFX_WideString::StringData::Create(int nLen) { |
| 16 // TODO(palmer): |nLen| should really be declared as |size_t|, or | 18 // TODO(palmer): |nLen| should really be declared as |size_t|, or |
| 17 // at least unsigned. | 19 // at least unsigned. |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 const FX_WCHAR* pstr = m_pData->m_String; | 634 const FX_WCHAR* pstr = m_pData->m_String; |
| 633 m_pData = StringData::Create(nNewLength); | 635 m_pData = StringData::Create(nNewLength); |
| 634 if (!m_pData) { | 636 if (!m_pData) { |
| 635 return 0; | 637 return 0; |
| 636 } | 638 } |
| 637 FXSYS_memcpy(m_pData->m_String, pstr, | 639 FXSYS_memcpy(m_pData->m_String, pstr, |
| 638 pOldData->m_nDataLength * sizeof(FX_WCHAR)); | 640 pOldData->m_nDataLength * sizeof(FX_WCHAR)); |
| 639 pOldData->Release(); | 641 pOldData->Release(); |
| 640 } | 642 } |
| 641 lpszStart = m_pData->m_String; | 643 lpszStart = m_pData->m_String; |
| 642 lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength); | 644 lpszEnd = m_pData->m_String + std::max(m_pData->m_nDataLength, nNewLength); |
| 643 { | 645 { |
| 644 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != | 646 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != |
| 645 NULL && | 647 NULL && |
| 646 lpszStart < lpszEnd) { | 648 lpszStart < lpszEnd) { |
| 647 FX_STRSIZE nBalance = | 649 FX_STRSIZE nBalance = |
| 648 nOldLength - | 650 nOldLength - |
| 649 (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen); | 651 (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen); |
| 650 FXSYS_memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen, | 652 FXSYS_memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen, |
| 651 nBalance * sizeof(FX_WCHAR)); | 653 nBalance * sizeof(FX_WCHAR)); |
| 652 FXSYS_memcpy(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_WCHAR)); | 654 FXSYS_memcpy(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_WCHAR)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 nMaxLen += FXSYS_wcslen(lpsz); | 753 nMaxLen += FXSYS_wcslen(lpsz); |
| 752 continue; | 754 continue; |
| 753 } | 755 } |
| 754 int nItemLen = 0; | 756 int nItemLen = 0; |
| 755 int nWidth = 0; | 757 int nWidth = 0; |
| 756 for (; *lpsz != 0; lpsz++) { | 758 for (; *lpsz != 0; lpsz++) { |
| 757 if (*lpsz == '#') { | 759 if (*lpsz == '#') { |
| 758 nMaxLen += 2; | 760 nMaxLen += 2; |
| 759 } else if (*lpsz == '*') { | 761 } else if (*lpsz == '*') { |
| 760 nWidth = va_arg(argList, int); | 762 nWidth = va_arg(argList, int); |
| 761 } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ') | 763 } else if (*lpsz != '-' && *lpsz != '+' && *lpsz != '0' && *lpsz != ' ') { |
| 762 ; | |
| 763 else { | |
| 764 break; | 764 break; |
| 765 } | 765 } |
| 766 } | 766 } |
| 767 if (nWidth == 0) { | 767 if (nWidth == 0) { |
| 768 nWidth = FXSYS_wtoi(lpsz); | 768 nWidth = FXSYS_wtoi(lpsz); |
| 769 while (std::iswdigit(*lpsz)) | 769 while (std::iswdigit(*lpsz)) |
| 770 ++lpsz; | 770 ++lpsz; |
| 771 } | 771 } |
| 772 if (nWidth < 0 || nWidth > 128 * 1024) { | 772 if (nWidth < 0 || nWidth > 128 * 1024) { |
| 773 lpszFormat = L"Bad width"; | 773 lpszFormat = L"Bad width"; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 return (CFX_CharMap*)&g_DefaultJISMapper; | 1052 return (CFX_CharMap*)&g_DefaultJISMapper; |
| 1053 case 936: | 1053 case 936: |
| 1054 return (CFX_CharMap*)&g_DefaultGBKMapper; | 1054 return (CFX_CharMap*)&g_DefaultGBKMapper; |
| 1055 case 949: | 1055 case 949: |
| 1056 return (CFX_CharMap*)&g_DefaultUHCMapper; | 1056 return (CFX_CharMap*)&g_DefaultUHCMapper; |
| 1057 case 950: | 1057 case 950: |
| 1058 return (CFX_CharMap*)&g_DefaultBig5Mapper; | 1058 return (CFX_CharMap*)&g_DefaultBig5Mapper; |
| 1059 } | 1059 } |
| 1060 return NULL; | 1060 return NULL; |
| 1061 } | 1061 } |
| OLD | NEW |