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> // For offsetof(). | 7 #include <stddef.h> // For offsetof(). |
8 | 8 |
9 #include "../../include/fxcrt/fx_basic.h" | 9 #include "../../include/fxcrt/fx_basic.h" |
10 #include "../../../third_party/base/numerics/safe_math.h" | 10 #include "../../../third_party/base/numerics/safe_math.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } else { | 125 } else { |
126 m_pData = NULL; | 126 m_pData = NULL; |
127 *this = stringSrc; | 127 *this = stringSrc; |
128 } | 128 } |
129 } | 129 } |
130 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& stringSrc) | 130 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& stringSrc) |
131 { | 131 { |
132 if (stringSrc.IsEmpty()) { | 132 if (stringSrc.IsEmpty()) { |
133 m_pData = NULL; | 133 m_pData = NULL; |
134 return; | 134 return; |
135 } else { | |
136 m_pData = NULL; | |
137 *this = stringSrc; | |
138 } | 135 } |
| 136 m_pData = NULL; |
| 137 *this = stringSrc; |
139 } | 138 } |
140 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, const CFX_ByteString
C& str2) | 139 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, const CFX_ByteString
C& str2) |
141 { | 140 { |
142 m_pData = NULL; | 141 m_pData = NULL; |
143 int nNewLen = str1.GetLength() + str2.GetLength(); | 142 int nNewLen = str1.GetLength() + str2.GetLength(); |
144 if (nNewLen == 0) { | 143 if (nNewLen == 0) { |
145 return; | 144 return; |
146 } | 145 } |
147 m_pData = StringData::Create(nNewLen); | 146 m_pData = StringData::Create(nNewLen); |
148 if (m_pData) { | 147 if (m_pData) { |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 { | 963 { |
965 if (m_pData == NULL) { | 964 if (m_pData == NULL) { |
966 return str.IsEmpty() ? 0 : -1; | 965 return str.IsEmpty() ? 0 : -1; |
967 } | 966 } |
968 int this_len = m_pData->m_nDataLength; | 967 int this_len = m_pData->m_nDataLength; |
969 int that_len = str.GetLength(); | 968 int that_len = str.GetLength(); |
970 int min_len = this_len < that_len ? this_len : that_len; | 969 int min_len = this_len < that_len ? this_len : that_len; |
971 for (int i = 0; i < min_len; i ++) { | 970 for (int i = 0; i < min_len; i ++) { |
972 if ((uint8_t)m_pData->m_String[i] < str.GetAt(i)) { | 971 if ((uint8_t)m_pData->m_String[i] < str.GetAt(i)) { |
973 return -1; | 972 return -1; |
974 } else if ((uint8_t)m_pData->m_String[i] > str.GetAt(i)) { | 973 } |
| 974 if ((uint8_t)m_pData->m_String[i] > str.GetAt(i)) { |
975 return 1; | 975 return 1; |
976 } | 976 } |
977 } | 977 } |
978 if (this_len < that_len) { | 978 if (this_len < that_len) { |
979 return -1; | 979 return -1; |
980 } else if (this_len > that_len) { | 980 } |
| 981 if (this_len > that_len) { |
981 return 1; | 982 return 1; |
982 } | 983 } |
983 return 0; | 984 return 0; |
984 } | 985 } |
985 void CFX_ByteString::TrimRight(const CFX_ByteStringC& lpszTargets) | 986 void CFX_ByteString::TrimRight(const CFX_ByteStringC& lpszTargets) |
986 { | 987 { |
987 if (m_pData == NULL || lpszTargets.IsEmpty()) { | 988 if (m_pData == NULL || lpszTargets.IsEmpty()) { |
988 return; | 989 return; |
989 } | 990 } |
990 CopyBeforeWrite(); | 991 CopyBeforeWrite(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 scale /= 10; | 1125 scale /= 10; |
1125 } | 1126 } |
1126 return buf_size; | 1127 return buf_size; |
1127 } | 1128 } |
1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) | 1129 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) |
1129 { | 1130 { |
1130 FX_CHAR buf[32]; | 1131 FX_CHAR buf[32]; |
1131 FX_STRSIZE len = FX_ftoa(d, buf); | 1132 FX_STRSIZE len = FX_ftoa(d, buf); |
1132 return CFX_ByteString(buf, len); | 1133 return CFX_ByteString(buf, len); |
1133 } | 1134 } |
OLD | NEW |