| 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 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 if (str) | 833 if (str) |
| 834 while (str[len]) | 834 while (str[len]) |
| 835 len++; | 835 len++; |
| 836 return len; | 836 return len; |
| 837 } | 837 } |
| 838 | 838 |
| 839 void CFX_WideString::TrimRight(const CFX_WideStringC& pTargets) { | 839 void CFX_WideString::TrimRight(const CFX_WideStringC& pTargets) { |
| 840 if (!m_pData || pTargets.IsEmpty()) { | 840 if (!m_pData || pTargets.IsEmpty()) { |
| 841 return; | 841 return; |
| 842 } | 842 } |
| 843 ReallocBeforeWrite(m_pData->m_nDataLength); | |
| 844 FX_STRSIZE pos = GetLength(); | 843 FX_STRSIZE pos = GetLength(); |
| 845 if (pos < 1) { | 844 if (pos < 1) { |
| 846 return; | 845 return; |
| 847 } | 846 } |
| 848 while (pos) { | 847 while (pos) { |
| 849 if (!FXSYS_wcschr(pTargets.c_str(), m_pData->m_String[pos - 1])) { | 848 if (!FXSYS_wcschr(pTargets.c_str(), m_pData->m_String[pos - 1])) { |
| 850 break; | 849 break; |
| 851 } | 850 } |
| 852 pos--; | 851 pos--; |
| 853 } | 852 } |
| 854 if (pos < m_pData->m_nDataLength) { | 853 if (pos < m_pData->m_nDataLength) { |
| 854 ReallocBeforeWrite(m_pData->m_nDataLength); |
| 855 m_pData->m_String[pos] = 0; | 855 m_pData->m_String[pos] = 0; |
| 856 m_pData->m_nDataLength = pos; | 856 m_pData->m_nDataLength = pos; |
| 857 } | 857 } |
| 858 } | 858 } |
| 859 | 859 |
| 860 void CFX_WideString::TrimRight(FX_WCHAR chTarget) { | 860 void CFX_WideString::TrimRight(FX_WCHAR chTarget) { |
| 861 FX_WCHAR str[2] = {chTarget, 0}; | 861 FX_WCHAR str[2] = {chTarget, 0}; |
| 862 TrimRight(str); | 862 TrimRight(str); |
| 863 } | 863 } |
| 864 | 864 |
| 865 void CFX_WideString::TrimRight() { | 865 void CFX_WideString::TrimRight() { |
| 866 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20"); | 866 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20"); |
| 867 } | 867 } |
| 868 | 868 |
| 869 void CFX_WideString::TrimLeft(const CFX_WideStringC& pTargets) { | 869 void CFX_WideString::TrimLeft(const CFX_WideStringC& pTargets) { |
| 870 if (!m_pData || pTargets.IsEmpty()) | 870 if (!m_pData || pTargets.IsEmpty()) |
| 871 return; | 871 return; |
| 872 | 872 |
| 873 FX_STRSIZE len = GetLength(); | 873 FX_STRSIZE len = GetLength(); |
| 874 if (len < 1) | 874 if (len < 1) |
| 875 return; | 875 return; |
| 876 | 876 |
| 877 ReallocBeforeWrite(len); | 877 FX_STRSIZE pos = 0; |
| 878 const FX_WCHAR* lpsz = m_pData->m_String; | 878 while (pos < len) { |
| 879 while (*lpsz != 0) { | 879 FX_STRSIZE i = 0; |
| 880 if (!FXSYS_wcschr(pTargets.c_str(), *lpsz)) { | 880 while (i < pTargets.GetLength() && pTargets[i] != m_pData->m_String[pos]) { |
| 881 i++; |
| 882 } |
| 883 if (i == pTargets.GetLength()) { |
| 881 break; | 884 break; |
| 882 } | 885 } |
| 883 lpsz++; | 886 pos++; |
| 884 } | 887 } |
| 885 if (lpsz != m_pData->m_String) { | 888 if (pos) { |
| 886 int nDataLength = | 889 ReallocBeforeWrite(len); |
| 887 m_pData->m_nDataLength - (FX_STRSIZE)(lpsz - m_pData->m_String); | 890 FX_STRSIZE nDataLength = len - pos; |
| 888 FXSYS_memmove(m_pData->m_String, lpsz, | 891 FXSYS_memmove(m_pData->m_String, m_pData->m_String + pos, |
| 889 (nDataLength + 1) * sizeof(FX_WCHAR)); | 892 (nDataLength + 1) * sizeof(FX_WCHAR)); |
| 890 m_pData->m_nDataLength = nDataLength; | 893 m_pData->m_nDataLength = nDataLength; |
| 891 } | 894 } |
| 892 } | 895 } |
| 893 | 896 |
| 894 void CFX_WideString::TrimLeft(FX_WCHAR chTarget) { | 897 void CFX_WideString::TrimLeft(FX_WCHAR chTarget) { |
| 895 FX_WCHAR str[2] = {chTarget, 0}; | 898 FX_WCHAR str[2] = {chTarget, 0}; |
| 896 TrimLeft(str); | 899 TrimLeft(str); |
| 897 } | 900 } |
| 898 | 901 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0); | 970 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0); |
| 968 CFX_WideString wstr; | 971 CFX_WideString wstr; |
| 969 if (dest_len) { | 972 if (dest_len) { |
| 970 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); | 973 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); |
| 971 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, | 974 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, |
| 972 dest_len); | 975 dest_len); |
| 973 wstr.ReleaseBuffer(dest_len); | 976 wstr.ReleaseBuffer(dest_len); |
| 974 } | 977 } |
| 975 return wstr; | 978 return wstr; |
| 976 } | 979 } |
| OLD | NEW |