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 <cctype> | 9 #include <cctype> |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 CFX_ByteString::CFX_ByteString(char ch) { | 133 CFX_ByteString::CFX_ByteString(char ch) { |
134 m_pData.Reset(StringData::Create(1)); | 134 m_pData.Reset(StringData::Create(1)); |
135 m_pData->m_String[0] = ch; | 135 m_pData->m_String[0] = ch; |
136 } | 136 } |
137 | 137 |
138 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& stringSrc) { | 138 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& stringSrc) { |
139 if (!stringSrc.IsEmpty()) { | 139 if (!stringSrc.IsEmpty()) { |
140 m_pData.Reset( | 140 m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); |
141 StringData::Create(stringSrc.GetCStr(), stringSrc.GetLength())); | |
142 } | 141 } |
143 } | 142 } |
144 | 143 |
145 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, | 144 CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, |
146 const CFX_ByteStringC& str2) { | 145 const CFX_ByteStringC& str2) { |
147 int nNewLen = str1.GetLength() + str2.GetLength(); | 146 int nNewLen = str1.GetLength() + str2.GetLength(); |
148 if (nNewLen == 0) | 147 if (nNewLen == 0) |
149 return; | 148 return; |
150 | 149 |
151 m_pData.Reset(StringData::Create(nNewLen)); | 150 m_pData.Reset(StringData::Create(nNewLen)); |
152 m_pData->CopyContents(str1.GetCStr(), str1.GetLength()); | 151 m_pData->CopyContents(str1.c_str(), str1.GetLength()); |
153 m_pData->CopyContentsAt(str1.GetLength(), str2.GetCStr(), str2.GetLength()); | 152 m_pData->CopyContentsAt(str1.GetLength(), str2.c_str(), str2.GetLength()); |
154 } | 153 } |
155 | 154 |
156 CFX_ByteString::~CFX_ByteString() {} | 155 CFX_ByteString::~CFX_ByteString() {} |
157 | 156 |
158 const CFX_ByteString& CFX_ByteString::operator=(const FX_CHAR* pStr) { | 157 const CFX_ByteString& CFX_ByteString::operator=(const FX_CHAR* pStr) { |
159 if (!pStr || !pStr[0]) | 158 if (!pStr || !pStr[0]) |
160 clear(); | 159 clear(); |
161 else | 160 else |
162 AssignCopy(pStr, FXSYS_strlen(pStr)); | 161 AssignCopy(pStr, FXSYS_strlen(pStr)); |
163 | 162 |
164 return *this; | 163 return *this; |
165 } | 164 } |
166 | 165 |
167 const CFX_ByteString& CFX_ByteString::operator=(const CFX_ByteStringC& str) { | 166 const CFX_ByteString& CFX_ByteString::operator=(const CFX_ByteStringC& str) { |
168 if (str.IsEmpty()) | 167 if (str.IsEmpty()) |
169 clear(); | 168 clear(); |
170 else | 169 else |
171 AssignCopy(str.GetCStr(), str.GetLength()); | 170 AssignCopy(str.c_str(), str.GetLength()); |
172 | 171 |
173 return *this; | 172 return *this; |
174 } | 173 } |
175 | 174 |
176 const CFX_ByteString& CFX_ByteString::operator=( | 175 const CFX_ByteString& CFX_ByteString::operator=( |
177 const CFX_ByteString& stringSrc) { | 176 const CFX_ByteString& stringSrc) { |
178 if (m_pData != stringSrc.m_pData) | 177 if (m_pData != stringSrc.m_pData) |
179 m_pData = stringSrc.m_pData; | 178 m_pData = stringSrc.m_pData; |
180 | 179 |
181 return *this; | 180 return *this; |
(...skipping 27 matching lines...) Expand all Loading... |
209 | 208 |
210 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& str) { | 209 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& str) { |
211 if (str.m_pData) | 210 if (str.m_pData) |
212 Concat(str.m_pData->m_String, str.m_pData->m_nDataLength); | 211 Concat(str.m_pData->m_String, str.m_pData->m_nDataLength); |
213 | 212 |
214 return *this; | 213 return *this; |
215 } | 214 } |
216 | 215 |
217 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteStringC& str) { | 216 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteStringC& str) { |
218 if (!str.IsEmpty()) | 217 if (!str.IsEmpty()) |
219 Concat(str.GetCStr(), str.GetLength()); | 218 Concat(str.c_str(), str.GetLength()); |
220 | 219 |
221 return *this; | 220 return *this; |
222 } | 221 } |
223 | 222 |
224 bool CFX_ByteString::operator==(const char* ptr) const { | 223 bool CFX_ByteString::operator==(const char* ptr) const { |
225 if (!m_pData) | 224 if (!m_pData) |
226 return !ptr || !ptr[0]; | 225 return !ptr || !ptr[0]; |
227 | 226 |
228 if (!ptr) | 227 if (!ptr) |
229 return m_pData->m_nDataLength == 0; | 228 return m_pData->m_nDataLength == 0; |
230 | 229 |
231 return FXSYS_strlen(ptr) == m_pData->m_nDataLength && | 230 return FXSYS_strlen(ptr) == m_pData->m_nDataLength && |
232 FXSYS_memcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; | 231 FXSYS_memcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; |
233 } | 232 } |
234 | 233 |
235 bool CFX_ByteString::operator==(const CFX_ByteStringC& str) const { | 234 bool CFX_ByteString::operator==(const CFX_ByteStringC& str) const { |
236 if (!m_pData) | 235 if (!m_pData) |
237 return str.IsEmpty(); | 236 return str.IsEmpty(); |
238 | 237 |
239 return m_pData->m_nDataLength == str.GetLength() && | 238 return m_pData->m_nDataLength == str.GetLength() && |
240 FXSYS_memcmp(m_pData->m_String, str.GetCStr(), str.GetLength()) == 0; | 239 FXSYS_memcmp(m_pData->m_String, str.c_str(), str.GetLength()) == 0; |
241 } | 240 } |
242 | 241 |
243 bool CFX_ByteString::operator==(const CFX_ByteString& other) const { | 242 bool CFX_ByteString::operator==(const CFX_ByteString& other) const { |
244 if (IsEmpty()) | 243 if (IsEmpty()) |
245 return other.IsEmpty(); | 244 return other.IsEmpty(); |
246 | 245 |
247 if (other.IsEmpty()) | 246 if (other.IsEmpty()) |
248 return false; | 247 return false; |
249 | 248 |
250 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && | 249 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && |
251 FXSYS_memcmp(other.m_pData->m_String, m_pData->m_String, | 250 FXSYS_memcmp(other.m_pData->m_String, m_pData->m_String, |
252 m_pData->m_nDataLength) == 0; | 251 m_pData->m_nDataLength) == 0; |
253 } | 252 } |
254 | 253 |
255 bool CFX_ByteString::EqualNoCase(const CFX_ByteStringC& str) const { | 254 bool CFX_ByteString::EqualNoCase(const CFX_ByteStringC& str) const { |
256 if (!m_pData) | 255 if (!m_pData) |
257 return str.IsEmpty(); | 256 return str.IsEmpty(); |
258 | 257 |
259 FX_STRSIZE len = str.GetLength(); | 258 FX_STRSIZE len = str.GetLength(); |
260 if (m_pData->m_nDataLength != len) | 259 if (m_pData->m_nDataLength != len) |
261 return false; | 260 return false; |
262 | 261 |
263 const uint8_t* pThis = (const uint8_t*)m_pData->m_String; | 262 const uint8_t* pThis = (const uint8_t*)m_pData->m_String; |
264 const uint8_t* pThat = str.GetPtr(); | 263 const uint8_t* pThat = str.raw_str(); |
265 for (FX_STRSIZE i = 0; i < len; i++) { | 264 for (FX_STRSIZE i = 0; i < len; i++) { |
266 if ((*pThis) != (*pThat)) { | 265 if ((*pThis) != (*pThat)) { |
267 uint8_t bThis = *pThis; | 266 uint8_t bThis = *pThis; |
268 if (bThis >= 'A' && bThis <= 'Z') | 267 if (bThis >= 'A' && bThis <= 'Z') |
269 bThis += 'a' - 'A'; | 268 bThis += 'a' - 'A'; |
270 | 269 |
271 uint8_t bThat = *pThat; | 270 uint8_t bThat = *pThat; |
272 if (bThat >= 'A' && bThat <= 'Z') | 271 if (bThat >= 'A' && bThat <= 'Z') |
273 bThat += 'a' - 'A'; | 272 bThat += 'a' - 'A'; |
274 | 273 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 FX_STRSIZE nStart) const { | 760 FX_STRSIZE nStart) const { |
762 if (!m_pData) | 761 if (!m_pData) |
763 return -1; | 762 return -1; |
764 | 763 |
765 FX_STRSIZE nLength = m_pData->m_nDataLength; | 764 FX_STRSIZE nLength = m_pData->m_nDataLength; |
766 if (nStart > nLength) | 765 if (nStart > nLength) |
767 return -1; | 766 return -1; |
768 | 767 |
769 const FX_CHAR* pStr = | 768 const FX_CHAR* pStr = |
770 FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, | 769 FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, |
771 pSub.GetCStr(), pSub.GetLength()); | 770 pSub.c_str(), pSub.GetLength()); |
772 return pStr ? (int)(pStr - m_pData->m_String) : -1; | 771 return pStr ? (int)(pStr - m_pData->m_String) : -1; |
773 } | 772 } |
774 | 773 |
775 void CFX_ByteString::MakeLower() { | 774 void CFX_ByteString::MakeLower() { |
776 if (!m_pData) | 775 if (!m_pData) |
777 return; | 776 return; |
778 | 777 |
779 ReallocBeforeWrite(m_pData->m_nDataLength); | 778 ReallocBeforeWrite(m_pData->m_nDataLength); |
780 FXSYS_strlwr(m_pData->m_String); | 779 FXSYS_strlwr(m_pData->m_String); |
781 } | 780 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 if (!m_pData || pOld.IsEmpty()) | 813 if (!m_pData || pOld.IsEmpty()) |
815 return 0; | 814 return 0; |
816 | 815 |
817 FX_STRSIZE nSourceLen = pOld.GetLength(); | 816 FX_STRSIZE nSourceLen = pOld.GetLength(); |
818 FX_STRSIZE nReplacementLen = pNew.GetLength(); | 817 FX_STRSIZE nReplacementLen = pNew.GetLength(); |
819 FX_STRSIZE nCount = 0; | 818 FX_STRSIZE nCount = 0; |
820 const FX_CHAR* pStart = m_pData->m_String; | 819 const FX_CHAR* pStart = m_pData->m_String; |
821 FX_CHAR* pEnd = m_pData->m_String + m_pData->m_nDataLength; | 820 FX_CHAR* pEnd = m_pData->m_String + m_pData->m_nDataLength; |
822 while (1) { | 821 while (1) { |
823 const FX_CHAR* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), | 822 const FX_CHAR* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), |
824 pOld.GetCStr(), nSourceLen); | 823 pOld.c_str(), nSourceLen); |
825 if (!pTarget) | 824 if (!pTarget) |
826 break; | 825 break; |
827 | 826 |
828 nCount++; | 827 nCount++; |
829 pStart = pTarget + nSourceLen; | 828 pStart = pTarget + nSourceLen; |
830 } | 829 } |
831 if (nCount == 0) | 830 if (nCount == 0) |
832 return 0; | 831 return 0; |
833 | 832 |
834 FX_STRSIZE nNewLength = | 833 FX_STRSIZE nNewLength = |
835 m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * nCount; | 834 m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * nCount; |
836 | 835 |
837 if (nNewLength == 0) { | 836 if (nNewLength == 0) { |
838 clear(); | 837 clear(); |
839 return nCount; | 838 return nCount; |
840 } | 839 } |
841 | 840 |
842 CFX_RetainPtr<StringData> pNewData(StringData::Create(nNewLength)); | 841 CFX_RetainPtr<StringData> pNewData(StringData::Create(nNewLength)); |
843 pStart = m_pData->m_String; | 842 pStart = m_pData->m_String; |
844 FX_CHAR* pDest = pNewData->m_String; | 843 FX_CHAR* pDest = pNewData->m_String; |
845 for (FX_STRSIZE i = 0; i < nCount; i++) { | 844 for (FX_STRSIZE i = 0; i < nCount; i++) { |
846 const FX_CHAR* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), | 845 const FX_CHAR* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), |
847 pOld.GetCStr(), nSourceLen); | 846 pOld.c_str(), nSourceLen); |
848 FXSYS_memcpy(pDest, pStart, pTarget - pStart); | 847 FXSYS_memcpy(pDest, pStart, pTarget - pStart); |
849 pDest += pTarget - pStart; | 848 pDest += pTarget - pStart; |
850 FXSYS_memcpy(pDest, pNew.GetCStr(), pNew.GetLength()); | 849 FXSYS_memcpy(pDest, pNew.c_str(), pNew.GetLength()); |
851 pDest += pNew.GetLength(); | 850 pDest += pNew.GetLength(); |
852 pStart = pTarget + nSourceLen; | 851 pStart = pTarget + nSourceLen; |
853 } | 852 } |
854 FXSYS_memcpy(pDest, pStart, pEnd - pStart); | 853 FXSYS_memcpy(pDest, pStart, pEnd - pStart); |
855 m_pData.Swap(pNewData); | 854 m_pData.Swap(pNewData); |
856 return nCount; | 855 return nCount; |
857 } | 856 } |
858 | 857 |
859 void CFX_ByteString::SetAt(FX_STRSIZE nIndex, FX_CHAR ch) { | 858 void CFX_ByteString::SetAt(FX_STRSIZE nIndex, FX_CHAR ch) { |
860 if (!m_pData) { | 859 if (!m_pData) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 fraction %= scale; | 1039 fraction %= scale; |
1041 scale /= 10; | 1040 scale /= 10; |
1042 } | 1041 } |
1043 return buf_size; | 1042 return buf_size; |
1044 } | 1043 } |
1045 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { | 1044 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { |
1046 FX_CHAR buf[32]; | 1045 FX_CHAR buf[32]; |
1047 FX_STRSIZE len = FX_ftoa(d, buf); | 1046 FX_STRSIZE len = FX_ftoa(d, buf); |
1048 return CFX_ByteString(buf, len); | 1047 return CFX_ByteString(buf, len); |
1049 } | 1048 } |
OLD | NEW |