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

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: 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
Lei Zhang 2016/04/11 21:47:57 BTW, there's an extra blank line vs bstring versio
Tom Sepez 2016/04/12 00:36:46 Done.
683 if (pstrSource == pstrEnd)
684 return 0;
685
686 ptrdiff_t copied = pstrSource - m_pData->m_String;
675 ReallocBeforeWrite(m_pData->m_nDataLength); 687 ReallocBeforeWrite(m_pData->m_nDataLength);
676 FX_WCHAR* pstrSource = m_pData->m_String; 688 pstrSource = m_pData->m_String + copied;
677 FX_WCHAR* pstrDest = m_pData->m_String; 689 pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
678 FX_WCHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength; 690
691 FX_WCHAR* pstrDest = pstrSource;
679 while (pstrSource < pstrEnd) { 692 while (pstrSource < pstrEnd) {
680 if (*pstrSource != chRemove) { 693 if (*pstrSource != chRemove) {
681 *pstrDest = *pstrSource; 694 *pstrDest = *pstrSource;
682 pstrDest++; 695 pstrDest++;
683 } 696 }
684 pstrSource++; 697 pstrSource++;
685 } 698 }
699
686 *pstrDest = 0; 700 *pstrDest = 0;
687 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest); 701 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest);
688 m_pData->m_nDataLength -= nCount; 702 m_pData->m_nDataLength -= nCount;
689 return nCount; 703 return nCount;
690 } 704 }
691 705
692 FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld, 706 FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld,
693 const CFX_WideStringC& pNew) { 707 const CFX_WideStringC& pNew) {
694 if (!m_pData || pOld.IsEmpty()) 708 if (!m_pData || pOld.IsEmpty())
695 return 0; 709 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); 984 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0);
971 CFX_WideString wstr; 985 CFX_WideString wstr;
972 if (dest_len) { 986 if (dest_len) {
973 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); 987 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len);
974 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, 988 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf,
975 dest_len); 989 dest_len);
976 wstr.ReleaseBuffer(dest_len); 990 wstr.ReleaseBuffer(dest_len);
977 } 991 }
978 return wstr; 992 return wstr;
979 } 993 }
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