| 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 #include <cctype> | 8 #include <cctype> |
| 9 | 9 |
| 10 #include "core/include/fxcrt/fx_basic.h" | 10 #include "core/include/fxcrt/fx_basic.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 m_pData = NULL; | 101 m_pData = NULL; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 CFX_ByteString::CFX_ByteString(char ch) { | 104 CFX_ByteString::CFX_ByteString(char ch) { |
| 105 m_pData = StringData::Create(1); | 105 m_pData = StringData::Create(1); |
| 106 if (m_pData) { | 106 if (m_pData) { |
| 107 m_pData->m_String[0] = ch; | 107 m_pData->m_String[0] = ch; |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 CFX_ByteString::CFX_ByteString(const CFX_ByteString& stringSrc) { | 110 CFX_ByteString::CFX_ByteString(const CFX_ByteString& stringSrc) { |
| 111 if (stringSrc.m_pData == NULL) { | 111 if (!stringSrc.m_pData) { |
| 112 m_pData = NULL; | 112 m_pData = NULL; |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 if (stringSrc.m_pData->m_nRefs >= 0) { | 115 if (stringSrc.m_pData->m_nRefs >= 0) { |
| 116 m_pData = stringSrc.m_pData; | 116 m_pData = stringSrc.m_pData; |
| 117 m_pData->Retain(); | 117 m_pData->Retain(); |
| 118 } else { | 118 } else { |
| 119 m_pData = NULL; | 119 m_pData = NULL; |
| 120 *this = stringSrc; | 120 *this = stringSrc; |
| 121 } | 121 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 m_pData = StringData::Create(nNewLen); | 138 m_pData = StringData::Create(nNewLen); |
| 139 if (m_pData) { | 139 if (m_pData) { |
| 140 FXSYS_memcpy(m_pData->m_String, str1.GetCStr(), str1.GetLength()); | 140 FXSYS_memcpy(m_pData->m_String, str1.GetCStr(), str1.GetLength()); |
| 141 FXSYS_memcpy(m_pData->m_String + str1.GetLength(), str2.GetCStr(), | 141 FXSYS_memcpy(m_pData->m_String + str1.GetLength(), str2.GetCStr(), |
| 142 str2.GetLength()); | 142 str2.GetLength()); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 const CFX_ByteString& CFX_ByteString::operator=(const FX_CHAR* lpsz) { | 145 const CFX_ByteString& CFX_ByteString::operator=(const FX_CHAR* lpsz) { |
| 146 if (lpsz == NULL || lpsz[0] == 0) { | 146 if (!lpsz || lpsz[0] == 0) { |
| 147 Empty(); | 147 Empty(); |
| 148 } else { | 148 } else { |
| 149 AssignCopy(FXSYS_strlen(lpsz), lpsz); | 149 AssignCopy(FXSYS_strlen(lpsz), lpsz); |
| 150 } | 150 } |
| 151 return *this; | 151 return *this; |
| 152 } | 152 } |
| 153 const CFX_ByteString& CFX_ByteString::operator=(const CFX_ByteStringC& str) { | 153 const CFX_ByteString& CFX_ByteString::operator=(const CFX_ByteStringC& str) { |
| 154 if (str.IsEmpty()) { | 154 if (str.IsEmpty()) { |
| 155 Empty(); | 155 Empty(); |
| 156 } else { | 156 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (lpsz) { | 196 if (lpsz) { |
| 197 ConcatInPlace(FXSYS_strlen(lpsz), lpsz); | 197 ConcatInPlace(FXSYS_strlen(lpsz), lpsz); |
| 198 } | 198 } |
| 199 return *this; | 199 return *this; |
| 200 } | 200 } |
| 201 const CFX_ByteString& CFX_ByteString::operator+=(char ch) { | 201 const CFX_ByteString& CFX_ByteString::operator+=(char ch) { |
| 202 ConcatInPlace(1, &ch); | 202 ConcatInPlace(1, &ch); |
| 203 return *this; | 203 return *this; |
| 204 } | 204 } |
| 205 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& string) { | 205 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& string) { |
| 206 if (string.m_pData == NULL) { | 206 if (!string.m_pData) { |
| 207 return *this; | 207 return *this; |
| 208 } | 208 } |
| 209 ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String); | 209 ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String); |
| 210 return *this; | 210 return *this; |
| 211 } | 211 } |
| 212 const CFX_ByteString& CFX_ByteString::operator+=( | 212 const CFX_ByteString& CFX_ByteString::operator+=( |
| 213 const CFX_ByteStringC& string) { | 213 const CFX_ByteStringC& string) { |
| 214 if (string.IsEmpty()) { | 214 if (string.IsEmpty()) { |
| 215 return *this; | 215 return *this; |
| 216 } | 216 } |
| 217 ConcatInPlace(string.GetLength(), string.GetCStr()); | 217 ConcatInPlace(string.GetLength(), string.GetCStr()); |
| 218 return *this; | 218 return *this; |
| 219 } | 219 } |
| 220 bool CFX_ByteString::Equal(const char* ptr) const { | 220 bool CFX_ByteString::Equal(const char* ptr) const { |
| 221 if (!m_pData) { | 221 if (!m_pData) { |
| 222 return !ptr || ptr[0] == '\0'; | 222 return !ptr || ptr[0] == '\0'; |
| 223 } | 223 } |
| 224 if (!ptr) { | 224 if (!ptr) { |
| 225 return m_pData->m_nDataLength == 0; | 225 return m_pData->m_nDataLength == 0; |
| 226 } | 226 } |
| 227 return FXSYS_strlen(ptr) == m_pData->m_nDataLength && | 227 return FXSYS_strlen(ptr) == m_pData->m_nDataLength && |
| 228 FXSYS_memcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; | 228 FXSYS_memcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; |
| 229 } | 229 } |
| 230 bool CFX_ByteString::Equal(const CFX_ByteStringC& str) const { | 230 bool CFX_ByteString::Equal(const CFX_ByteStringC& str) const { |
| 231 if (m_pData == NULL) { | 231 if (!m_pData) { |
| 232 return str.IsEmpty(); | 232 return str.IsEmpty(); |
| 233 } | 233 } |
| 234 return m_pData->m_nDataLength == str.GetLength() && | 234 return m_pData->m_nDataLength == str.GetLength() && |
| 235 FXSYS_memcmp(m_pData->m_String, str.GetCStr(), str.GetLength()) == 0; | 235 FXSYS_memcmp(m_pData->m_String, str.GetCStr(), str.GetLength()) == 0; |
| 236 } | 236 } |
| 237 bool CFX_ByteString::Equal(const CFX_ByteString& other) const { | 237 bool CFX_ByteString::Equal(const CFX_ByteString& other) const { |
| 238 if (IsEmpty()) { | 238 if (IsEmpty()) { |
| 239 return other.IsEmpty(); | 239 return other.IsEmpty(); |
| 240 } | 240 } |
| 241 if (other.IsEmpty()) { | 241 if (other.IsEmpty()) { |
| 242 return false; | 242 return false; |
| 243 } | 243 } |
| 244 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && | 244 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && |
| 245 FXSYS_memcmp(other.m_pData->m_String, m_pData->m_String, | 245 FXSYS_memcmp(other.m_pData->m_String, m_pData->m_String, |
| 246 m_pData->m_nDataLength) == 0; | 246 m_pData->m_nDataLength) == 0; |
| 247 } | 247 } |
| 248 void CFX_ByteString::Empty() { | 248 void CFX_ByteString::Empty() { |
| 249 if (m_pData) { | 249 if (m_pData) { |
| 250 m_pData->Release(); | 250 m_pData->Release(); |
| 251 m_pData = NULL; | 251 m_pData = NULL; |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 bool CFX_ByteString::EqualNoCase(const CFX_ByteStringC& str) const { | 254 bool CFX_ByteString::EqualNoCase(const CFX_ByteStringC& str) const { |
| 255 if (m_pData == NULL) { | 255 if (!m_pData) { |
| 256 return str.IsEmpty(); | 256 return str.IsEmpty(); |
| 257 } | 257 } |
| 258 FX_STRSIZE len = str.GetLength(); | 258 FX_STRSIZE len = str.GetLength(); |
| 259 if (m_pData->m_nDataLength != len) { | 259 if (m_pData->m_nDataLength != len) { |
| 260 return false; | 260 return false; |
| 261 } | 261 } |
| 262 const uint8_t* pThis = (const uint8_t*)m_pData->m_String; | 262 const uint8_t* pThis = (const uint8_t*)m_pData->m_String; |
| 263 const uint8_t* pThat = str.GetPtr(); | 263 const uint8_t* pThat = str.GetPtr(); |
| 264 for (FX_STRSIZE i = 0; i < len; i++) { | 264 for (FX_STRSIZE i = 0; i < len; i++) { |
| 265 if ((*pThis) != (*pThat)) { | 265 if ((*pThis) != (*pThat)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 281 return true; | 281 return true; |
| 282 } | 282 } |
| 283 void CFX_ByteString::AssignCopy(FX_STRSIZE nSrcLen, | 283 void CFX_ByteString::AssignCopy(FX_STRSIZE nSrcLen, |
| 284 const FX_CHAR* lpszSrcData) { | 284 const FX_CHAR* lpszSrcData) { |
| 285 AllocBeforeWrite(nSrcLen); | 285 AllocBeforeWrite(nSrcLen); |
| 286 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen); | 286 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen); |
| 287 m_pData->m_nDataLength = nSrcLen; | 287 m_pData->m_nDataLength = nSrcLen; |
| 288 m_pData->m_String[nSrcLen] = 0; | 288 m_pData->m_String[nSrcLen] = 0; |
| 289 } | 289 } |
| 290 void CFX_ByteString::CopyBeforeWrite() { | 290 void CFX_ByteString::CopyBeforeWrite() { |
| 291 if (m_pData == NULL || m_pData->m_nRefs <= 1) { | 291 if (!m_pData || m_pData->m_nRefs <= 1) { |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 StringData* pData = m_pData; | 294 StringData* pData = m_pData; |
| 295 m_pData->Release(); | 295 m_pData->Release(); |
| 296 FX_STRSIZE nDataLength = pData->m_nDataLength; | 296 FX_STRSIZE nDataLength = pData->m_nDataLength; |
| 297 m_pData = StringData::Create(nDataLength); | 297 m_pData = StringData::Create(nDataLength); |
| 298 if (m_pData) { | 298 if (m_pData) { |
| 299 FXSYS_memcpy(m_pData->m_String, pData->m_String, nDataLength + 1); | 299 FXSYS_memcpy(m_pData->m_String, pData->m_String, nDataLength + 1); |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 void CFX_ByteString::AllocBeforeWrite(FX_STRSIZE nLen) { | 302 void CFX_ByteString::AllocBeforeWrite(FX_STRSIZE nLen) { |
| 303 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nLen) { | 303 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nLen) { |
| 304 return; | 304 return; |
| 305 } | 305 } |
| 306 Empty(); | 306 Empty(); |
| 307 m_pData = StringData::Create(nLen); | 307 m_pData = StringData::Create(nLen); |
| 308 } | 308 } |
| 309 void CFX_ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) { | 309 void CFX_ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) { |
| 310 if (m_pData == NULL) { | 310 if (!m_pData) { |
| 311 return; | 311 return; |
| 312 } | 312 } |
| 313 CopyBeforeWrite(); | 313 CopyBeforeWrite(); |
| 314 if (nNewLength == -1) { | 314 if (nNewLength == -1) { |
| 315 nNewLength = FXSYS_strlen((const FX_CHAR*)m_pData->m_String); | 315 nNewLength = FXSYS_strlen((const FX_CHAR*)m_pData->m_String); |
| 316 } | 316 } |
| 317 if (nNewLength == 0) { | 317 if (nNewLength == 0) { |
| 318 Empty(); | 318 Empty(); |
| 319 return; | 319 return; |
| 320 } | 320 } |
| 321 FXSYS_assert(nNewLength <= m_pData->m_nAllocLength); | 321 FXSYS_assert(nNewLength <= m_pData->m_nAllocLength); |
| 322 m_pData->m_nDataLength = nNewLength; | 322 m_pData->m_nDataLength = nNewLength; |
| 323 m_pData->m_String[nNewLength] = 0; | 323 m_pData->m_String[nNewLength] = 0; |
| 324 } | 324 } |
| 325 void CFX_ByteString::Reserve(FX_STRSIZE len) { | 325 void CFX_ByteString::Reserve(FX_STRSIZE len) { |
| 326 GetBuffer(len); | 326 GetBuffer(len); |
| 327 ReleaseBuffer(GetLength()); | 327 ReleaseBuffer(GetLength()); |
| 328 } | 328 } |
| 329 FX_CHAR* CFX_ByteString::GetBuffer(FX_STRSIZE nMinBufLength) { | 329 FX_CHAR* CFX_ByteString::GetBuffer(FX_STRSIZE nMinBufLength) { |
| 330 if (m_pData == NULL && nMinBufLength == 0) { | 330 if (!m_pData && nMinBufLength == 0) { |
| 331 return NULL; | 331 return NULL; |
| 332 } | 332 } |
| 333 if (m_pData && m_pData->m_nRefs <= 1 && | 333 if (m_pData && m_pData->m_nRefs <= 1 && |
| 334 m_pData->m_nAllocLength >= nMinBufLength) { | 334 m_pData->m_nAllocLength >= nMinBufLength) { |
| 335 return m_pData->m_String; | 335 return m_pData->m_String; |
| 336 } | 336 } |
| 337 if (m_pData == NULL) { | 337 if (!m_pData) { |
| 338 m_pData = StringData::Create(nMinBufLength); | 338 m_pData = StringData::Create(nMinBufLength); |
| 339 if (!m_pData) { | 339 if (!m_pData) { |
| 340 return NULL; | 340 return NULL; |
| 341 } | 341 } |
| 342 m_pData->m_nDataLength = 0; | 342 m_pData->m_nDataLength = 0; |
| 343 m_pData->m_String[0] = 0; | 343 m_pData->m_String[0] = 0; |
| 344 return m_pData->m_String; | 344 return m_pData->m_String; |
| 345 } | 345 } |
| 346 StringData* pOldData = m_pData; | 346 StringData* pOldData = m_pData; |
| 347 FX_STRSIZE nOldLen = pOldData->m_nDataLength; | 347 FX_STRSIZE nOldLen = pOldData->m_nDataLength; |
| 348 if (nMinBufLength < nOldLen) { | 348 if (nMinBufLength < nOldLen) { |
| 349 nMinBufLength = nOldLen; | 349 nMinBufLength = nOldLen; |
| 350 } | 350 } |
| 351 m_pData = StringData::Create(nMinBufLength); | 351 m_pData = StringData::Create(nMinBufLength); |
| 352 if (!m_pData) { | 352 if (!m_pData) { |
| 353 return NULL; | 353 return NULL; |
| 354 } | 354 } |
| 355 FXSYS_memcpy(m_pData->m_String, pOldData->m_String, (nOldLen + 1)); | 355 FXSYS_memcpy(m_pData->m_String, pOldData->m_String, (nOldLen + 1)); |
| 356 m_pData->m_nDataLength = nOldLen; | 356 m_pData->m_nDataLength = nOldLen; |
| 357 pOldData->Release(); | 357 pOldData->Release(); |
| 358 return m_pData->m_String; | 358 return m_pData->m_String; |
| 359 } | 359 } |
| 360 FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount) { | 360 FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount) { |
| 361 if (m_pData == NULL) { | 361 if (!m_pData) { |
| 362 return 0; | 362 return 0; |
| 363 } | 363 } |
| 364 if (nIndex < 0) { | 364 if (nIndex < 0) { |
| 365 nIndex = 0; | 365 nIndex = 0; |
| 366 } | 366 } |
| 367 FX_STRSIZE nOldLength = m_pData->m_nDataLength; | 367 FX_STRSIZE nOldLength = m_pData->m_nDataLength; |
| 368 if (nCount > 0 && nIndex < nOldLength) { | 368 if (nCount > 0 && nIndex < nOldLength) { |
| 369 FX_STRSIZE mLength = nIndex + nCount; | 369 FX_STRSIZE mLength = nIndex + nCount; |
| 370 if (mLength >= nOldLength) { | 370 if (mLength >= nOldLength) { |
| 371 m_pData->m_nDataLength = nIndex; | 371 m_pData->m_nDataLength = nIndex; |
| 372 return m_pData->m_nDataLength; | 372 return m_pData->m_nDataLength; |
| 373 } | 373 } |
| 374 CopyBeforeWrite(); | 374 CopyBeforeWrite(); |
| 375 int nBytesToCopy = nOldLength - mLength + 1; | 375 int nBytesToCopy = nOldLength - mLength + 1; |
| 376 FXSYS_memmove(m_pData->m_String + nIndex, m_pData->m_String + mLength, | 376 FXSYS_memmove(m_pData->m_String + nIndex, m_pData->m_String + mLength, |
| 377 nBytesToCopy); | 377 nBytesToCopy); |
| 378 m_pData->m_nDataLength = nOldLength - nCount; | 378 m_pData->m_nDataLength = nOldLength - nCount; |
| 379 } | 379 } |
| 380 return m_pData->m_nDataLength; | 380 return m_pData->m_nDataLength; |
| 381 } | 381 } |
| 382 void CFX_ByteString::ConcatInPlace(FX_STRSIZE nSrcLen, | 382 void CFX_ByteString::ConcatInPlace(FX_STRSIZE nSrcLen, |
| 383 const FX_CHAR* lpszSrcData) { | 383 const FX_CHAR* lpszSrcData) { |
| 384 if (nSrcLen == 0 || lpszSrcData == NULL) { | 384 if (nSrcLen == 0 || !lpszSrcData) { |
| 385 return; | 385 return; |
| 386 } | 386 } |
| 387 if (m_pData == NULL) { | 387 if (!m_pData) { |
| 388 m_pData = StringData::Create(nSrcLen); | 388 m_pData = StringData::Create(nSrcLen); |
| 389 if (!m_pData) { | 389 if (!m_pData) { |
| 390 return; | 390 return; |
| 391 } | 391 } |
| 392 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen); | 392 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen); |
| 393 return; | 393 return; |
| 394 } | 394 } |
| 395 if (m_pData->m_nRefs > 1 || | 395 if (m_pData->m_nRefs > 1 || |
| 396 m_pData->m_nDataLength + nSrcLen > m_pData->m_nAllocLength) { | 396 m_pData->m_nDataLength + nSrcLen > m_pData->m_nAllocLength) { |
| 397 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcData); | 397 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcData); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 413 // Don't release until done copying, might be one of the arguments. | 413 // Don't release until done copying, might be one of the arguments. |
| 414 StringData* pOldData = m_pData; | 414 StringData* pOldData = m_pData; |
| 415 m_pData = StringData::Create(nNewLen); | 415 m_pData = StringData::Create(nNewLen); |
| 416 if (m_pData) { | 416 if (m_pData) { |
| 417 memcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len); | 417 memcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len); |
| 418 memcpy(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len); | 418 memcpy(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len); |
| 419 } | 419 } |
| 420 pOldData->Release(); | 420 pOldData->Release(); |
| 421 } | 421 } |
| 422 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst) const { | 422 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst) const { |
| 423 if (m_pData == NULL) { | 423 if (!m_pData) { |
| 424 return CFX_ByteString(); | 424 return CFX_ByteString(); |
| 425 } | 425 } |
| 426 return Mid(nFirst, m_pData->m_nDataLength - nFirst); | 426 return Mid(nFirst, m_pData->m_nDataLength - nFirst); |
| 427 } | 427 } |
| 428 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { | 428 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { |
| 429 if (nFirst < 0) { | 429 if (nFirst < 0) { |
| 430 nFirst = 0; | 430 nFirst = 0; |
| 431 } | 431 } |
| 432 if (nCount < 0) { | 432 if (nCount < 0) { |
| 433 nCount = 0; | 433 nCount = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 446 return dest; | 446 return dest; |
| 447 } | 447 } |
| 448 void CFX_ByteString::AllocCopy(CFX_ByteString& dest, | 448 void CFX_ByteString::AllocCopy(CFX_ByteString& dest, |
| 449 FX_STRSIZE nCopyLen, | 449 FX_STRSIZE nCopyLen, |
| 450 FX_STRSIZE nCopyIndex) const { | 450 FX_STRSIZE nCopyIndex) const { |
| 451 // |FX_STRSIZE| is currently typedef'd as in |int|. TODO(palmer): It | 451 // |FX_STRSIZE| is currently typedef'd as in |int|. TODO(palmer): It |
| 452 // should be a |size_t|, or at least unsigned. | 452 // should be a |size_t|, or at least unsigned. |
| 453 if (nCopyLen == 0 || nCopyLen < 0) { | 453 if (nCopyLen == 0 || nCopyLen < 0) { |
| 454 return; | 454 return; |
| 455 } | 455 } |
| 456 ASSERT(dest.m_pData == NULL); | 456 ASSERT(!dest.m_pData); |
| 457 dest.m_pData = StringData::Create(nCopyLen); | 457 dest.m_pData = StringData::Create(nCopyLen); |
| 458 if (dest.m_pData) { | 458 if (dest.m_pData) { |
| 459 FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex, | 459 FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex, |
| 460 nCopyLen); | 460 nCopyLen); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 #define FORCE_ANSI 0x10000 | 463 #define FORCE_ANSI 0x10000 |
| 464 #define FORCE_UNICODE 0x20000 | 464 #define FORCE_UNICODE 0x20000 |
| 465 #define FORCE_INT64 0x40000 | 465 #define FORCE_INT64 0x40000 |
| 466 void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) { | 466 void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 nItemLen = 2; | 551 nItemLen = 2; |
| 552 va_arg(argList, int); | 552 va_arg(argList, int); |
| 553 break; | 553 break; |
| 554 case 'c' | FORCE_UNICODE: | 554 case 'c' | FORCE_UNICODE: |
| 555 case 'C' | FORCE_UNICODE: | 555 case 'C' | FORCE_UNICODE: |
| 556 nItemLen = 2; | 556 nItemLen = 2; |
| 557 va_arg(argList, int); | 557 va_arg(argList, int); |
| 558 break; | 558 break; |
| 559 case 's': { | 559 case 's': { |
| 560 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); | 560 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); |
| 561 if (pstrNextArg == NULL) { | 561 if (pstrNextArg) { |
| 562 nItemLen = 6; | |
| 563 } else { | |
| 564 nItemLen = FXSYS_strlen(pstrNextArg); | 562 nItemLen = FXSYS_strlen(pstrNextArg); |
| 565 if (nItemLen < 1) { | 563 if (nItemLen < 1) { |
| 566 nItemLen = 1; | 564 nItemLen = 1; |
| 567 } | 565 } |
| 566 } else { |
| 567 nItemLen = 6; |
| 568 } | 568 } |
| 569 } break; | 569 } break; |
| 570 case 'S': { | 570 case 'S': { |
| 571 FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); | 571 FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); |
| 572 if (pstrNextArg == NULL) { | 572 if (pstrNextArg) { |
| 573 nItemLen = 6; | |
| 574 } else { | |
| 575 nItemLen = FXSYS_wcslen(pstrNextArg); | 573 nItemLen = FXSYS_wcslen(pstrNextArg); |
| 576 if (nItemLen < 1) { | 574 if (nItemLen < 1) { |
| 577 nItemLen = 1; | 575 nItemLen = 1; |
| 578 } | 576 } |
| 577 } else { |
| 578 nItemLen = 6; |
| 579 } | 579 } |
| 580 } break; | 580 } break; |
| 581 case 's' | FORCE_ANSI: | 581 case 's' | FORCE_ANSI: |
| 582 case 'S' | FORCE_ANSI: { | 582 case 'S' | FORCE_ANSI: { |
| 583 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); | 583 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); |
| 584 if (pstrNextArg == NULL) { | 584 if (pstrNextArg) { |
| 585 nItemLen = 6; | |
| 586 } else { | |
| 587 nItemLen = FXSYS_strlen(pstrNextArg); | 585 nItemLen = FXSYS_strlen(pstrNextArg); |
| 588 if (nItemLen < 1) { | 586 if (nItemLen < 1) { |
| 589 nItemLen = 1; | 587 nItemLen = 1; |
| 590 } | 588 } |
| 589 } else { |
| 590 nItemLen = 6; |
| 591 } | 591 } |
| 592 } break; | 592 } break; |
| 593 case 's' | FORCE_UNICODE: | 593 case 's' | FORCE_UNICODE: |
| 594 case 'S' | FORCE_UNICODE: { | 594 case 'S' | FORCE_UNICODE: { |
| 595 FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); | 595 FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); |
| 596 if (pstrNextArg == NULL) { | 596 if (pstrNextArg) { |
| 597 nItemLen = 6; | |
| 598 } else { | |
| 599 nItemLen = FXSYS_wcslen(pstrNextArg); | 597 nItemLen = FXSYS_wcslen(pstrNextArg); |
| 600 if (nItemLen < 1) { | 598 if (nItemLen < 1) { |
| 601 nItemLen = 1; | 599 nItemLen = 1; |
| 602 } | 600 } |
| 601 } else { |
| 602 nItemLen = 6; |
| 603 } | 603 } |
| 604 } break; | 604 } break; |
| 605 } | 605 } |
| 606 if (nItemLen != 0) { | 606 if (nItemLen != 0) { |
| 607 if (nPrecision != 0 && nItemLen > nPrecision) { | 607 if (nPrecision != 0 && nItemLen > nPrecision) { |
| 608 nItemLen = nPrecision; | 608 nItemLen = nPrecision; |
| 609 } | 609 } |
| 610 if (nItemLen < nWidth) { | 610 if (nItemLen < nWidth) { |
| 611 nItemLen = nWidth; | 611 nItemLen = nWidth; |
| 612 } | 612 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 FX_STRSIZE CFX_ByteString::Insert(FX_STRSIZE nIndex, FX_CHAR ch) { | 684 FX_STRSIZE CFX_ByteString::Insert(FX_STRSIZE nIndex, FX_CHAR ch) { |
| 685 CopyBeforeWrite(); | 685 CopyBeforeWrite(); |
| 686 if (nIndex < 0) { | 686 if (nIndex < 0) { |
| 687 nIndex = 0; | 687 nIndex = 0; |
| 688 } | 688 } |
| 689 FX_STRSIZE nNewLength = m_pData ? m_pData->m_nDataLength : 0; | 689 FX_STRSIZE nNewLength = m_pData ? m_pData->m_nDataLength : 0; |
| 690 if (nIndex > nNewLength) { | 690 if (nIndex > nNewLength) { |
| 691 nIndex = nNewLength; | 691 nIndex = nNewLength; |
| 692 } | 692 } |
| 693 nNewLength++; | 693 nNewLength++; |
| 694 if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) { | 694 if (!m_pData || m_pData->m_nAllocLength < nNewLength) { |
| 695 StringData* pOldData = m_pData; | 695 StringData* pOldData = m_pData; |
| 696 const FX_CHAR* pstr = m_pData->m_String; | 696 const FX_CHAR* pstr = m_pData->m_String; |
| 697 m_pData = StringData::Create(nNewLength); | 697 m_pData = StringData::Create(nNewLength); |
| 698 if (!m_pData) { | 698 if (!m_pData) { |
| 699 return 0; | 699 return 0; |
| 700 } | 700 } |
| 701 if (pOldData) { | 701 if (pOldData) { |
| 702 FXSYS_memmove(m_pData->m_String, pstr, (pOldData->m_nDataLength + 1)); | 702 FXSYS_memmove(m_pData->m_String, pstr, (pOldData->m_nDataLength + 1)); |
| 703 pOldData->Release(); | 703 pOldData->Release(); |
| 704 } else { | 704 } else { |
| 705 m_pData->m_String[0] = 0; | 705 m_pData->m_String[0] = 0; |
| 706 } | 706 } |
| 707 } | 707 } |
| 708 FXSYS_memmove(m_pData->m_String + nIndex + 1, m_pData->m_String + nIndex, | 708 FXSYS_memmove(m_pData->m_String + nIndex + 1, m_pData->m_String + nIndex, |
| 709 (nNewLength - nIndex)); | 709 (nNewLength - nIndex)); |
| 710 m_pData->m_String[nIndex] = ch; | 710 m_pData->m_String[nIndex] = ch; |
| 711 m_pData->m_nDataLength = nNewLength; | 711 m_pData->m_nDataLength = nNewLength; |
| 712 return nNewLength; | 712 return nNewLength; |
| 713 } | 713 } |
| 714 CFX_ByteString CFX_ByteString::Right(FX_STRSIZE nCount) const { | 714 CFX_ByteString CFX_ByteString::Right(FX_STRSIZE nCount) const { |
| 715 if (m_pData == NULL) { | 715 if (!m_pData) { |
| 716 return CFX_ByteString(); | 716 return CFX_ByteString(); |
| 717 } | 717 } |
| 718 if (nCount < 0) { | 718 if (nCount < 0) { |
| 719 nCount = 0; | 719 nCount = 0; |
| 720 } | 720 } |
| 721 if (nCount >= m_pData->m_nDataLength) { | 721 if (nCount >= m_pData->m_nDataLength) { |
| 722 return *this; | 722 return *this; |
| 723 } | 723 } |
| 724 CFX_ByteString dest; | 724 CFX_ByteString dest; |
| 725 AllocCopy(dest, nCount, m_pData->m_nDataLength - nCount); | 725 AllocCopy(dest, nCount, m_pData->m_nDataLength - nCount); |
| 726 return dest; | 726 return dest; |
| 727 } | 727 } |
| 728 CFX_ByteString CFX_ByteString::Left(FX_STRSIZE nCount) const { | 728 CFX_ByteString CFX_ByteString::Left(FX_STRSIZE nCount) const { |
| 729 if (m_pData == NULL) { | 729 if (!m_pData) { |
| 730 return CFX_ByteString(); | 730 return CFX_ByteString(); |
| 731 } | 731 } |
| 732 if (nCount < 0) { | 732 if (nCount < 0) { |
| 733 nCount = 0; | 733 nCount = 0; |
| 734 } | 734 } |
| 735 if (nCount >= m_pData->m_nDataLength) { | 735 if (nCount >= m_pData->m_nDataLength) { |
| 736 return *this; | 736 return *this; |
| 737 } | 737 } |
| 738 CFX_ByteString dest; | 738 CFX_ByteString dest; |
| 739 AllocCopy(dest, nCount, 0); | 739 AllocCopy(dest, nCount, 0); |
| 740 return dest; | 740 return dest; |
| 741 } | 741 } |
| 742 FX_STRSIZE CFX_ByteString::Find(FX_CHAR ch, FX_STRSIZE nStart) const { | 742 FX_STRSIZE CFX_ByteString::Find(FX_CHAR ch, FX_STRSIZE nStart) const { |
| 743 if (m_pData == NULL) { | 743 if (!m_pData) { |
| 744 return -1; | 744 return -1; |
| 745 } | 745 } |
| 746 FX_STRSIZE nLength = m_pData->m_nDataLength; | 746 FX_STRSIZE nLength = m_pData->m_nDataLength; |
| 747 if (nStart >= nLength) { | 747 if (nStart >= nLength) { |
| 748 return -1; | 748 return -1; |
| 749 } | 749 } |
| 750 const FX_CHAR* lpsz = FXSYS_strchr(m_pData->m_String + nStart, ch); | 750 const FX_CHAR* lpsz = FXSYS_strchr(m_pData->m_String + nStart, ch); |
| 751 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); | 751 return lpsz ? (int)(lpsz - m_pData->m_String) : -1; |
| 752 } | 752 } |
| 753 FX_STRSIZE CFX_ByteString::ReverseFind(FX_CHAR ch) const { | 753 FX_STRSIZE CFX_ByteString::ReverseFind(FX_CHAR ch) const { |
| 754 if (m_pData == NULL) { | 754 if (!m_pData) { |
| 755 return -1; | 755 return -1; |
| 756 } | 756 } |
| 757 FX_STRSIZE nLength = m_pData->m_nDataLength; | 757 FX_STRSIZE nLength = m_pData->m_nDataLength; |
| 758 while (nLength) { | 758 while (nLength) { |
| 759 if (m_pData->m_String[nLength - 1] == ch) { | 759 if (m_pData->m_String[nLength - 1] == ch) { |
| 760 return nLength - 1; | 760 return nLength - 1; |
| 761 } | 761 } |
| 762 nLength--; | 762 nLength--; |
| 763 } | 763 } |
| 764 return -1; | 764 return -1; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 781 if (i == len2) { | 781 if (i == len2) { |
| 782 return str1; | 782 return str1; |
| 783 } | 783 } |
| 784 } | 784 } |
| 785 str1++; | 785 str1++; |
| 786 } | 786 } |
| 787 return NULL; | 787 return NULL; |
| 788 } | 788 } |
| 789 FX_STRSIZE CFX_ByteString::Find(const CFX_ByteStringC& lpszSub, | 789 FX_STRSIZE CFX_ByteString::Find(const CFX_ByteStringC& lpszSub, |
| 790 FX_STRSIZE nStart) const { | 790 FX_STRSIZE nStart) const { |
| 791 if (m_pData == NULL) { | 791 if (!m_pData) { |
| 792 return -1; | 792 return -1; |
| 793 } | 793 } |
| 794 FX_STRSIZE nLength = m_pData->m_nDataLength; | 794 FX_STRSIZE nLength = m_pData->m_nDataLength; |
| 795 if (nStart > nLength) { | 795 if (nStart > nLength) { |
| 796 return -1; | 796 return -1; |
| 797 } | 797 } |
| 798 const FX_CHAR* lpsz = | 798 const FX_CHAR* lpsz = |
| 799 FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, | 799 FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, |
| 800 lpszSub.GetCStr(), lpszSub.GetLength()); | 800 lpszSub.GetCStr(), lpszSub.GetLength()); |
| 801 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); | 801 return lpsz ? (int)(lpsz - m_pData->m_String) : -1; |
| 802 } | 802 } |
| 803 void CFX_ByteString::MakeLower() { | 803 void CFX_ByteString::MakeLower() { |
| 804 if (m_pData == NULL) { | 804 if (!m_pData) { |
| 805 return; | 805 return; |
| 806 } | 806 } |
| 807 CopyBeforeWrite(); | 807 CopyBeforeWrite(); |
| 808 if (GetLength() < 1) { | 808 if (GetLength() < 1) { |
| 809 return; | 809 return; |
| 810 } | 810 } |
| 811 FXSYS_strlwr(m_pData->m_String); | 811 FXSYS_strlwr(m_pData->m_String); |
| 812 } | 812 } |
| 813 void CFX_ByteString::MakeUpper() { | 813 void CFX_ByteString::MakeUpper() { |
| 814 if (m_pData == NULL) { | 814 if (!m_pData) { |
| 815 return; | 815 return; |
| 816 } | 816 } |
| 817 CopyBeforeWrite(); | 817 CopyBeforeWrite(); |
| 818 if (GetLength() < 1) { | 818 if (GetLength() < 1) { |
| 819 return; | 819 return; |
| 820 } | 820 } |
| 821 FXSYS_strupr(m_pData->m_String); | 821 FXSYS_strupr(m_pData->m_String); |
| 822 } | 822 } |
| 823 FX_STRSIZE CFX_ByteString::Remove(FX_CHAR chRemove) { | 823 FX_STRSIZE CFX_ByteString::Remove(FX_CHAR chRemove) { |
| 824 if (m_pData == NULL) { | 824 if (!m_pData) { |
| 825 return 0; | 825 return 0; |
| 826 } | 826 } |
| 827 CopyBeforeWrite(); | 827 CopyBeforeWrite(); |
| 828 if (GetLength() < 1) { | 828 if (GetLength() < 1) { |
| 829 return 0; | 829 return 0; |
| 830 } | 830 } |
| 831 FX_CHAR* pstrSource = m_pData->m_String; | 831 FX_CHAR* pstrSource = m_pData->m_String; |
| 832 FX_CHAR* pstrDest = m_pData->m_String; | 832 FX_CHAR* pstrDest = m_pData->m_String; |
| 833 FX_CHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength; | 833 FX_CHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength; |
| 834 while (pstrSource < pstrEnd) { | 834 while (pstrSource < pstrEnd) { |
| 835 if (*pstrSource != chRemove) { | 835 if (*pstrSource != chRemove) { |
| 836 *pstrDest = *pstrSource; | 836 *pstrDest = *pstrSource; |
| 837 pstrDest++; | 837 pstrDest++; |
| 838 } | 838 } |
| 839 pstrSource++; | 839 pstrSource++; |
| 840 } | 840 } |
| 841 *pstrDest = 0; | 841 *pstrDest = 0; |
| 842 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest); | 842 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest); |
| 843 m_pData->m_nDataLength -= nCount; | 843 m_pData->m_nDataLength -= nCount; |
| 844 return nCount; | 844 return nCount; |
| 845 } | 845 } |
| 846 FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& lpszOld, | 846 FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& lpszOld, |
| 847 const CFX_ByteStringC& lpszNew) { | 847 const CFX_ByteStringC& lpszNew) { |
| 848 if (m_pData == NULL) { | 848 if (!m_pData) { |
| 849 return 0; | 849 return 0; |
| 850 } | 850 } |
| 851 if (lpszOld.IsEmpty()) { | 851 if (lpszOld.IsEmpty()) { |
| 852 return 0; | 852 return 0; |
| 853 } | 853 } |
| 854 FX_STRSIZE nSourceLen = lpszOld.GetLength(); | 854 FX_STRSIZE nSourceLen = lpszOld.GetLength(); |
| 855 FX_STRSIZE nReplacementLen = lpszNew.GetLength(); | 855 FX_STRSIZE nReplacementLen = lpszNew.GetLength(); |
| 856 FX_STRSIZE nCount = 0; | 856 FX_STRSIZE nCount = 0; |
| 857 const FX_CHAR* pStart = m_pData->m_String; | 857 const FX_CHAR* pStart = m_pData->m_String; |
| 858 FX_CHAR* pEnd = m_pData->m_String + m_pData->m_nDataLength; | 858 FX_CHAR* pEnd = m_pData->m_String + m_pData->m_nDataLength; |
| 859 while (1) { | 859 while (1) { |
| 860 const FX_CHAR* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), | 860 const FX_CHAR* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), |
| 861 lpszOld.GetCStr(), nSourceLen); | 861 lpszOld.GetCStr(), nSourceLen); |
| 862 if (pTarget == NULL) { | 862 if (!pTarget) { |
| 863 break; | 863 break; |
| 864 } | 864 } |
| 865 nCount++; | 865 nCount++; |
| 866 pStart = pTarget + nSourceLen; | 866 pStart = pTarget + nSourceLen; |
| 867 } | 867 } |
| 868 if (nCount == 0) { | 868 if (nCount == 0) { |
| 869 return 0; | 869 return 0; |
| 870 } | 870 } |
| 871 FX_STRSIZE nNewLength = | 871 FX_STRSIZE nNewLength = |
| 872 m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * nCount; | 872 m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * nCount; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 888 FXSYS_memcpy(pDest, lpszNew.GetCStr(), lpszNew.GetLength()); | 888 FXSYS_memcpy(pDest, lpszNew.GetCStr(), lpszNew.GetLength()); |
| 889 pDest += lpszNew.GetLength(); | 889 pDest += lpszNew.GetLength(); |
| 890 pStart = pTarget + nSourceLen; | 890 pStart = pTarget + nSourceLen; |
| 891 } | 891 } |
| 892 FXSYS_memcpy(pDest, pStart, pEnd - pStart); | 892 FXSYS_memcpy(pDest, pStart, pEnd - pStart); |
| 893 m_pData->Release(); | 893 m_pData->Release(); |
| 894 m_pData = pNewData; | 894 m_pData = pNewData; |
| 895 return nCount; | 895 return nCount; |
| 896 } | 896 } |
| 897 void CFX_ByteString::SetAt(FX_STRSIZE nIndex, FX_CHAR ch) { | 897 void CFX_ByteString::SetAt(FX_STRSIZE nIndex, FX_CHAR ch) { |
| 898 if (m_pData == NULL) { | 898 if (!m_pData) { |
| 899 return; | 899 return; |
| 900 } | 900 } |
| 901 FXSYS_assert(nIndex >= 0); | 901 FXSYS_assert(nIndex >= 0); |
| 902 FXSYS_assert(nIndex < m_pData->m_nDataLength); | 902 FXSYS_assert(nIndex < m_pData->m_nDataLength); |
| 903 CopyBeforeWrite(); | 903 CopyBeforeWrite(); |
| 904 m_pData->m_String[nIndex] = ch; | 904 m_pData->m_String[nIndex] = ch; |
| 905 } | 905 } |
| 906 CFX_WideString CFX_ByteString::UTF8Decode() const { | 906 CFX_WideString CFX_ByteString::UTF8Decode() const { |
| 907 CFX_UTF8Decoder decoder; | 907 CFX_UTF8Decoder decoder; |
| 908 for (FX_STRSIZE i = 0; i < GetLength(); i++) { | 908 for (FX_STRSIZE i = 0; i < GetLength(); i++) { |
| 909 decoder.Input((uint8_t)m_pData->m_String[i]); | 909 decoder.Input((uint8_t)m_pData->m_String[i]); |
| 910 } | 910 } |
| 911 return decoder.GetResult(); | 911 return decoder.GetResult(); |
| 912 } | 912 } |
| 913 CFX_ByteString CFX_ByteString::FromUnicode(const FX_WCHAR* str, | 913 CFX_ByteString CFX_ByteString::FromUnicode(const FX_WCHAR* str, |
| 914 FX_STRSIZE len) { | 914 FX_STRSIZE len) { |
| 915 if (len < 0) { | 915 if (len < 0) { |
| 916 len = FXSYS_wcslen(str); | 916 len = FXSYS_wcslen(str); |
| 917 } | 917 } |
| 918 CFX_ByteString bstr; | 918 CFX_ByteString bstr; |
| 919 bstr.ConvertFrom(CFX_WideString(str, len)); | 919 bstr.ConvertFrom(CFX_WideString(str, len)); |
| 920 return bstr; | 920 return bstr; |
| 921 } | 921 } |
| 922 CFX_ByteString CFX_ByteString::FromUnicode(const CFX_WideString& str) { | 922 CFX_ByteString CFX_ByteString::FromUnicode(const CFX_WideString& str) { |
| 923 return FromUnicode(str.c_str(), str.GetLength()); | 923 return FromUnicode(str.c_str(), str.GetLength()); |
| 924 } | 924 } |
| 925 void CFX_ByteString::ConvertFrom(const CFX_WideString& str, | 925 void CFX_ByteString::ConvertFrom(const CFX_WideString& str, |
| 926 CFX_CharMap* pCharMap) { | 926 CFX_CharMap* pCharMap) { |
| 927 if (pCharMap == NULL) { | 927 if (!pCharMap) { |
| 928 pCharMap = CFX_CharMap::GetDefaultMapper(); | 928 pCharMap = CFX_CharMap::GetDefaultMapper(); |
| 929 } | 929 } |
| 930 *this = (*pCharMap->m_GetByteString)(pCharMap, str); | 930 *this = (*pCharMap->m_GetByteString)(pCharMap, str); |
| 931 } | 931 } |
| 932 int CFX_ByteString::Compare(const CFX_ByteStringC& str) const { | 932 int CFX_ByteString::Compare(const CFX_ByteStringC& str) const { |
| 933 if (m_pData == NULL) { | 933 if (!m_pData) { |
| 934 return str.IsEmpty() ? 0 : -1; | 934 return str.IsEmpty() ? 0 : -1; |
| 935 } | 935 } |
| 936 int this_len = m_pData->m_nDataLength; | 936 int this_len = m_pData->m_nDataLength; |
| 937 int that_len = str.GetLength(); | 937 int that_len = str.GetLength(); |
| 938 int min_len = this_len < that_len ? this_len : that_len; | 938 int min_len = this_len < that_len ? this_len : that_len; |
| 939 for (int i = 0; i < min_len; i++) { | 939 for (int i = 0; i < min_len; i++) { |
| 940 if ((uint8_t)m_pData->m_String[i] < str.GetAt(i)) { | 940 if ((uint8_t)m_pData->m_String[i] < str.GetAt(i)) { |
| 941 return -1; | 941 return -1; |
| 942 } | 942 } |
| 943 if ((uint8_t)m_pData->m_String[i] > str.GetAt(i)) { | 943 if ((uint8_t)m_pData->m_String[i] > str.GetAt(i)) { |
| 944 return 1; | 944 return 1; |
| 945 } | 945 } |
| 946 } | 946 } |
| 947 if (this_len < that_len) { | 947 if (this_len < that_len) { |
| 948 return -1; | 948 return -1; |
| 949 } | 949 } |
| 950 if (this_len > that_len) { | 950 if (this_len > that_len) { |
| 951 return 1; | 951 return 1; |
| 952 } | 952 } |
| 953 return 0; | 953 return 0; |
| 954 } | 954 } |
| 955 void CFX_ByteString::TrimRight(const CFX_ByteStringC& lpszTargets) { | 955 void CFX_ByteString::TrimRight(const CFX_ByteStringC& lpszTargets) { |
| 956 if (m_pData == NULL || lpszTargets.IsEmpty()) { | 956 if (!m_pData || lpszTargets.IsEmpty()) { |
| 957 return; | 957 return; |
| 958 } | 958 } |
| 959 CopyBeforeWrite(); | 959 CopyBeforeWrite(); |
| 960 FX_STRSIZE pos = GetLength(); | 960 FX_STRSIZE pos = GetLength(); |
| 961 if (pos < 1) { | 961 if (pos < 1) { |
| 962 return; | 962 return; |
| 963 } | 963 } |
| 964 while (pos) { | 964 while (pos) { |
| 965 FX_STRSIZE i = 0; | 965 FX_STRSIZE i = 0; |
| 966 while (i < lpszTargets.GetLength() && | 966 while (i < lpszTargets.GetLength() && |
| (...skipping 10 matching lines...) Expand all Loading... |
| 977 m_pData->m_nDataLength = pos; | 977 m_pData->m_nDataLength = pos; |
| 978 } | 978 } |
| 979 } | 979 } |
| 980 void CFX_ByteString::TrimRight(FX_CHAR chTarget) { | 980 void CFX_ByteString::TrimRight(FX_CHAR chTarget) { |
| 981 TrimRight(CFX_ByteStringC(chTarget)); | 981 TrimRight(CFX_ByteStringC(chTarget)); |
| 982 } | 982 } |
| 983 void CFX_ByteString::TrimRight() { | 983 void CFX_ByteString::TrimRight() { |
| 984 TrimRight("\x09\x0a\x0b\x0c\x0d\x20"); | 984 TrimRight("\x09\x0a\x0b\x0c\x0d\x20"); |
| 985 } | 985 } |
| 986 void CFX_ByteString::TrimLeft(const CFX_ByteStringC& lpszTargets) { | 986 void CFX_ByteString::TrimLeft(const CFX_ByteStringC& lpszTargets) { |
| 987 if (m_pData == NULL) { | 987 if (!m_pData) { |
| 988 return; | 988 return; |
| 989 } | 989 } |
| 990 if (lpszTargets.IsEmpty()) { | 990 if (lpszTargets.IsEmpty()) { |
| 991 return; | 991 return; |
| 992 } | 992 } |
| 993 CopyBeforeWrite(); | 993 CopyBeforeWrite(); |
| 994 FX_STRSIZE len = GetLength(); | 994 FX_STRSIZE len = GetLength(); |
| 995 if (len < 1) { | 995 if (len < 1) { |
| 996 return; | 996 return; |
| 997 } | 997 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 fraction %= scale; | 1087 fraction %= scale; |
| 1088 scale /= 10; | 1088 scale /= 10; |
| 1089 } | 1089 } |
| 1090 return buf_size; | 1090 return buf_size; |
| 1091 } | 1091 } |
| 1092 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { | 1092 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { |
| 1093 FX_CHAR buf[32]; | 1093 FX_CHAR buf[32]; |
| 1094 FX_STRSIZE len = FX_ftoa(d, buf); | 1094 FX_STRSIZE len = FX_ftoa(d, buf); |
| 1095 return CFX_ByteString(buf, len); | 1095 return CFX_ByteString(buf, len); |
| 1096 } | 1096 } |
| OLD | NEW |