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

Side by Side Diff: core/fxcrt/fx_basic_bstring.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 | « no previous file | core/fxcrt/fx_basic_bstring_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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 return; 712 return;
713 713
714 ReallocBeforeWrite(m_pData->m_nDataLength); 714 ReallocBeforeWrite(m_pData->m_nDataLength);
715 FXSYS_strupr(m_pData->m_String); 715 FXSYS_strupr(m_pData->m_String);
716 } 716 }
717 717
718 FX_STRSIZE CFX_ByteString::Remove(FX_CHAR chRemove) { 718 FX_STRSIZE CFX_ByteString::Remove(FX_CHAR chRemove) {
719 if (!m_pData || m_pData->m_nDataLength < 1) 719 if (!m_pData || m_pData->m_nDataLength < 1)
720 return 0; 720 return 0;
721 721
722 FX_CHAR* pstrSource = m_pData->m_String;
723 FX_CHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
724 while (pstrSource < pstrEnd) {
725 if (*pstrSource == chRemove)
726 break;
727 pstrSource++;
728 }
729 if (pstrSource == pstrEnd)
730 return 0;
731
732 ptrdiff_t copied = pstrSource - m_pData->m_String;
722 ReallocBeforeWrite(m_pData->m_nDataLength); 733 ReallocBeforeWrite(m_pData->m_nDataLength);
723 FX_CHAR* pstrSource = m_pData->m_String; 734 pstrSource = m_pData->m_String + copied;
724 FX_CHAR* pstrDest = m_pData->m_String; 735 pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
725 FX_CHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength; 736
737 FX_CHAR* pstrDest = pstrSource;
726 while (pstrSource < pstrEnd) { 738 while (pstrSource < pstrEnd) {
727 if (*pstrSource != chRemove) { 739 if (*pstrSource != chRemove) {
728 *pstrDest = *pstrSource; 740 *pstrDest = *pstrSource;
729 pstrDest++; 741 pstrDest++;
730 } 742 }
731 pstrSource++; 743 pstrSource++;
732 } 744 }
745
733 *pstrDest = 0; 746 *pstrDest = 0;
734 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest); 747 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest);
735 m_pData->m_nDataLength -= nCount; 748 m_pData->m_nDataLength -= nCount;
736 return nCount; 749 return nCount;
737 } 750 }
738 751
739 FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& pOld, 752 FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& pOld,
740 const CFX_ByteStringC& pNew) { 753 const CFX_ByteStringC& pNew) {
741 if (!m_pData || pOld.IsEmpty()) 754 if (!m_pData || pOld.IsEmpty())
742 return 0; 755 return 0;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 fraction %= scale; 987 fraction %= scale;
975 scale /= 10; 988 scale /= 10;
976 } 989 }
977 return buf_size; 990 return buf_size;
978 } 991 }
979 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { 992 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) {
980 FX_CHAR buf[32]; 993 FX_CHAR buf[32];
981 FX_STRSIZE len = FX_ftoa(d, buf); 994 FX_STRSIZE len = FX_ftoa(d, buf);
982 return CFX_ByteString(buf, len); 995 return CFX_ByteString(buf, len);
983 } 996 }
OLDNEW
« no previous file with comments | « no previous file | core/fxcrt/fx_basic_bstring_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698