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

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

Issue 1877993002: Make CFX_{Byte,Wide}String::Remove() no-touch if possible (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Extra blank line. Created 4 years, 8 months 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/fxcrt/fx_basic_bstring_unittest.cpp ('k') | core/fxcrt/fx_basic_wstring_unittest.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> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 return; 665 return;
666 666
667 ReallocBeforeWrite(m_pData->m_nDataLength); 667 ReallocBeforeWrite(m_pData->m_nDataLength);
668 FXSYS_wcsupr(m_pData->m_String); 668 FXSYS_wcsupr(m_pData->m_String);
669 } 669 }
670 670
671 FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) { 671 FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) {
672 if (!m_pData || m_pData->m_nDataLength < 1) 672 if (!m_pData || m_pData->m_nDataLength < 1)
673 return 0; 673 return 0;
674 674
675 FX_WCHAR* pstrSource = m_pData->m_String;
676 FX_WCHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
677 while (pstrSource < pstrEnd) {
678 if (*pstrSource == chRemove)
679 break;
680 pstrSource++;
681 }
682 if (pstrSource == pstrEnd)
683 return 0;
684
685 ptrdiff_t copied = pstrSource - m_pData->m_String;
675 ReallocBeforeWrite(m_pData->m_nDataLength); 686 ReallocBeforeWrite(m_pData->m_nDataLength);
676 FX_WCHAR* pstrSource = m_pData->m_String; 687 pstrSource = m_pData->m_String + copied;
677 FX_WCHAR* pstrDest = m_pData->m_String; 688 pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
678 FX_WCHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength; 689
690 FX_WCHAR* pstrDest = pstrSource;
679 while (pstrSource < pstrEnd) { 691 while (pstrSource < pstrEnd) {
680 if (*pstrSource != chRemove) { 692 if (*pstrSource != chRemove) {
681 *pstrDest = *pstrSource; 693 *pstrDest = *pstrSource;
682 pstrDest++; 694 pstrDest++;
683 } 695 }
684 pstrSource++; 696 pstrSource++;
685 } 697 }
698
686 *pstrDest = 0; 699 *pstrDest = 0;
687 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest); 700 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest);
688 m_pData->m_nDataLength -= nCount; 701 m_pData->m_nDataLength -= nCount;
689 return nCount; 702 return nCount;
690 } 703 }
691 704
692 FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld, 705 FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld,
693 const CFX_WideStringC& pNew) { 706 const CFX_WideStringC& pNew) {
694 if (!m_pData || pOld.IsEmpty()) 707 if (!m_pData || pOld.IsEmpty())
695 return 0; 708 return 0;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0); 983 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0);
971 CFX_WideString wstr; 984 CFX_WideString wstr;
972 if (dest_len) { 985 if (dest_len) {
973 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); 986 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len);
974 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, 987 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf,
975 dest_len); 988 dest_len);
976 wstr.ReleaseBuffer(dest_len); 989 wstr.ReleaseBuffer(dest_len);
977 } 990 }
978 return wstr; 991 return wstr;
979 } 992 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_bstring_unittest.cpp ('k') | core/fxcrt/fx_basic_wstring_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698