| 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> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cctype> | 10 #include <cctype> |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return 0; | 633 return 0; |
| 634 } | 634 } |
| 635 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); | 635 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); |
| 636 if (nSourceLen == 0) { | 636 if (nSourceLen == 0) { |
| 637 return 0; | 637 return 0; |
| 638 } | 638 } |
| 639 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0; | 639 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0; |
| 640 FX_STRSIZE nCount = 0; | 640 FX_STRSIZE nCount = 0; |
| 641 FX_WCHAR* lpszStart = m_pData->m_String; | 641 FX_WCHAR* lpszStart = m_pData->m_String; |
| 642 FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength; | 642 FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength; |
| 643 FX_WCHAR* lpszTarget; | 643 while (lpszStart < lpszEnd) { |
| 644 { | 644 FX_WCHAR* lpszTarget = FXSYS_wcsstr(lpszStart, lpszOld); |
| 645 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) && | 645 if (!lpszTarget) |
| 646 lpszStart < lpszEnd) { | 646 break; |
| 647 nCount++; | 647 nCount++; |
| 648 lpszStart = lpszTarget + nSourceLen; | 648 lpszStart = lpszTarget + nSourceLen; |
| 649 } | |
| 650 } | 649 } |
| 651 if (nCount > 0) { | 650 if (nCount > 0) { |
| 652 CopyBeforeWrite(); | 651 CopyBeforeWrite(); |
| 653 FX_STRSIZE nOldLength = m_pData->m_nDataLength; | 652 FX_STRSIZE nOldLength = m_pData->m_nDataLength; |
| 654 FX_STRSIZE nNewLength = | 653 FX_STRSIZE nNewLength = |
| 655 nOldLength + (nReplacementLen - nSourceLen) * nCount; | 654 nOldLength + (nReplacementLen - nSourceLen) * nCount; |
| 656 if (m_pData->m_nAllocLength < nNewLength || m_pData->m_nRefs > 1) { | 655 if (m_pData->m_nAllocLength < nNewLength || m_pData->m_nRefs > 1) { |
| 657 StringData* pOldData = m_pData; | 656 StringData* pOldData = m_pData; |
| 658 const FX_WCHAR* pstr = m_pData->m_String; | 657 const FX_WCHAR* pstr = m_pData->m_String; |
| 659 m_pData = StringData::Create(nNewLength); | 658 m_pData = StringData::Create(nNewLength); |
| 660 if (!m_pData) { | 659 if (!m_pData) { |
| 661 return 0; | 660 return 0; |
| 662 } | 661 } |
| 663 FXSYS_memcpy(m_pData->m_String, pstr, | 662 FXSYS_memcpy(m_pData->m_String, pstr, |
| 664 pOldData->m_nDataLength * sizeof(FX_WCHAR)); | 663 pOldData->m_nDataLength * sizeof(FX_WCHAR)); |
| 665 pOldData->Release(); | 664 pOldData->Release(); |
| 666 } | 665 } |
| 667 lpszStart = m_pData->m_String; | 666 lpszStart = m_pData->m_String; |
| 668 lpszEnd = m_pData->m_String + std::max(m_pData->m_nDataLength, nNewLength); | 667 lpszEnd = m_pData->m_String + std::max(m_pData->m_nDataLength, nNewLength); |
| 669 { | 668 { |
| 670 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != | 669 while (lpszStart < lpszEnd) { |
| 671 NULL && | 670 FX_WCHAR* lpszTarget = FXSYS_wcsstr(lpszStart, lpszOld); |
| 672 lpszStart < lpszEnd) { | 671 if (!lpszTarget) |
| 672 break; |
| 673 FX_STRSIZE nBalance = | 673 FX_STRSIZE nBalance = |
| 674 nOldLength - | 674 nOldLength - |
| 675 (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen); | 675 (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen); |
| 676 FXSYS_memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen, | 676 FXSYS_memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen, |
| 677 nBalance * sizeof(FX_WCHAR)); | 677 nBalance * sizeof(FX_WCHAR)); |
| 678 FXSYS_memcpy(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_WCHAR)); | 678 FXSYS_memcpy(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_WCHAR)); |
| 679 lpszStart = lpszTarget + nReplacementLen; | 679 lpszStart = lpszTarget + nReplacementLen; |
| 680 lpszStart[nBalance] = 0; | 680 lpszStart[nBalance] = 0; |
| 681 nOldLength += (nReplacementLen - nSourceLen); | 681 nOldLength += (nReplacementLen - nSourceLen); |
| 682 } | 682 } |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 int dest_len = | 1041 int dest_len = |
| 1042 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0); | 1042 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0); |
| 1043 CFX_WideString wstr; | 1043 CFX_WideString wstr; |
| 1044 if (dest_len) { | 1044 if (dest_len) { |
| 1045 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); | 1045 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); |
| 1046 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len); | 1046 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len); |
| 1047 wstr.ReleaseBuffer(dest_len); | 1047 wstr.ReleaseBuffer(dest_len); |
| 1048 } | 1048 } |
| 1049 return wstr; | 1049 return wstr; |
| 1050 } | 1050 } |
| OLD | NEW |