| 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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 if (this_len > that_len) { | 834 if (this_len > that_len) { |
| 835 return 1; | 835 return 1; |
| 836 } | 836 } |
| 837 return 0; | 837 return 0; |
| 838 } | 838 } |
| 839 | 839 |
| 840 void CFX_ByteString::TrimRight(const CFX_ByteStringC& pTargets) { | 840 void CFX_ByteString::TrimRight(const CFX_ByteStringC& pTargets) { |
| 841 if (!m_pData || pTargets.IsEmpty()) { | 841 if (!m_pData || pTargets.IsEmpty()) { |
| 842 return; | 842 return; |
| 843 } | 843 } |
| 844 ReallocBeforeWrite(m_pData->m_nDataLength); | |
| 845 FX_STRSIZE pos = GetLength(); | 844 FX_STRSIZE pos = GetLength(); |
| 846 if (pos < 1) { | 845 if (pos < 1) { |
| 847 return; | 846 return; |
| 848 } | 847 } |
| 849 while (pos) { | 848 while (pos) { |
| 850 FX_STRSIZE i = 0; | 849 FX_STRSIZE i = 0; |
| 851 while (i < pTargets.GetLength() && | 850 while (i < pTargets.GetLength() && |
| 852 pTargets[i] != m_pData->m_String[pos - 1]) { | 851 pTargets[i] != m_pData->m_String[pos - 1]) { |
| 853 i++; | 852 i++; |
| 854 } | 853 } |
| 855 if (i == pTargets.GetLength()) { | 854 if (i == pTargets.GetLength()) { |
| 856 break; | 855 break; |
| 857 } | 856 } |
| 858 pos--; | 857 pos--; |
| 859 } | 858 } |
| 860 if (pos < m_pData->m_nDataLength) { | 859 if (pos < m_pData->m_nDataLength) { |
| 860 ReallocBeforeWrite(m_pData->m_nDataLength); |
| 861 m_pData->m_String[pos] = 0; | 861 m_pData->m_String[pos] = 0; |
| 862 m_pData->m_nDataLength = pos; | 862 m_pData->m_nDataLength = pos; |
| 863 } | 863 } |
| 864 } | 864 } |
| 865 | 865 |
| 866 void CFX_ByteString::TrimRight(FX_CHAR chTarget) { | 866 void CFX_ByteString::TrimRight(FX_CHAR chTarget) { |
| 867 TrimRight(CFX_ByteStringC(chTarget)); | 867 TrimRight(CFX_ByteStringC(chTarget)); |
| 868 } | 868 } |
| 869 | 869 |
| 870 void CFX_ByteString::TrimRight() { | 870 void CFX_ByteString::TrimRight() { |
| 871 TrimRight("\x09\x0a\x0b\x0c\x0d\x20"); | 871 TrimRight("\x09\x0a\x0b\x0c\x0d\x20"); |
| 872 } | 872 } |
| 873 | 873 |
| 874 void CFX_ByteString::TrimLeft(const CFX_ByteStringC& pTargets) { | 874 void CFX_ByteString::TrimLeft(const CFX_ByteStringC& pTargets) { |
| 875 if (!m_pData || pTargets.IsEmpty()) | 875 if (!m_pData || pTargets.IsEmpty()) |
| 876 return; | 876 return; |
| 877 | 877 |
| 878 FX_STRSIZE len = GetLength(); | 878 FX_STRSIZE len = GetLength(); |
| 879 if (len < 1) | 879 if (len < 1) |
| 880 return; | 880 return; |
| 881 | 881 |
| 882 ReallocBeforeWrite(len); | |
| 883 FX_STRSIZE pos = 0; | 882 FX_STRSIZE pos = 0; |
| 884 while (pos < len) { | 883 while (pos < len) { |
| 885 FX_STRSIZE i = 0; | 884 FX_STRSIZE i = 0; |
| 886 while (i < pTargets.GetLength() && pTargets[i] != m_pData->m_String[pos]) { | 885 while (i < pTargets.GetLength() && pTargets[i] != m_pData->m_String[pos]) { |
| 887 i++; | 886 i++; |
| 888 } | 887 } |
| 889 if (i == pTargets.GetLength()) { | 888 if (i == pTargets.GetLength()) { |
| 890 break; | 889 break; |
| 891 } | 890 } |
| 892 pos++; | 891 pos++; |
| 893 } | 892 } |
| 894 if (pos) { | 893 if (pos) { |
| 894 ReallocBeforeWrite(len); |
| 895 FX_STRSIZE nDataLength = len - pos; | 895 FX_STRSIZE nDataLength = len - pos; |
| 896 FXSYS_memmove(m_pData->m_String, m_pData->m_String + pos, | 896 FXSYS_memmove(m_pData->m_String, m_pData->m_String + pos, |
| 897 (nDataLength + 1) * sizeof(FX_CHAR)); | 897 (nDataLength + 1) * sizeof(FX_CHAR)); |
| 898 m_pData->m_nDataLength = nDataLength; | 898 m_pData->m_nDataLength = nDataLength; |
| 899 } | 899 } |
| 900 } | 900 } |
| 901 | 901 |
| 902 void CFX_ByteString::TrimLeft(FX_CHAR chTarget) { | 902 void CFX_ByteString::TrimLeft(FX_CHAR chTarget) { |
| 903 TrimLeft(CFX_ByteStringC(chTarget)); | 903 TrimLeft(CFX_ByteStringC(chTarget)); |
| 904 } | 904 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 fraction %= scale; | 974 fraction %= scale; |
| 975 scale /= 10; | 975 scale /= 10; |
| 976 } | 976 } |
| 977 return buf_size; | 977 return buf_size; |
| 978 } | 978 } |
| 979 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { | 979 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { |
| 980 FX_CHAR buf[32]; | 980 FX_CHAR buf[32]; |
| 981 FX_STRSIZE len = FX_ftoa(d, buf); | 981 FX_STRSIZE len = FX_ftoa(d, buf); |
| 982 return CFX_ByteString(buf, len); | 982 return CFX_ByteString(buf, len); |
| 983 } | 983 } |
| OLD | NEW |