| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after 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) { | 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 (!m_pData) |
| 430 nFirst = 0; | 430 return CFX_ByteString(); |
| 431 } | 431 |
| 432 if (nCount < 0) { | 432 nFirst = std::min(std::max(0, nFirst), m_pData->m_nDataLength); |
| 433 nCount = 0; | 433 nCount = std::min(std::max(0, nCount), m_pData->m_nDataLength - nFirst); |
| 434 } | 434 if (nFirst == 0 && nCount == m_pData->m_nDataLength) |
| 435 if (nFirst + nCount > m_pData->m_nDataLength) { | |
| 436 nCount = m_pData->m_nDataLength - nFirst; | |
| 437 } | |
| 438 if (nFirst > m_pData->m_nDataLength) { | |
| 439 nCount = 0; | |
| 440 } | |
| 441 if (nFirst == 0 && nFirst + nCount == m_pData->m_nDataLength) { | |
| 442 return *this; | 435 return *this; |
| 443 } | 436 |
| 444 CFX_ByteString dest; | 437 CFX_ByteString dest; |
| 445 AllocCopy(dest, nCount, nFirst); | 438 AllocCopy(dest, nCount, nFirst); |
| 446 return dest; | 439 return dest; |
| 447 } | 440 } |
| 448 void CFX_ByteString::AllocCopy(CFX_ByteString& dest, | 441 void CFX_ByteString::AllocCopy(CFX_ByteString& dest, |
| 449 FX_STRSIZE nCopyLen, | 442 FX_STRSIZE nCopyLen, |
| 450 FX_STRSIZE nCopyIndex) const { | 443 FX_STRSIZE nCopyIndex) const { |
| 451 // |FX_STRSIZE| is currently typedef'd as in |int|. TODO(palmer): It | 444 // |FX_STRSIZE| is currently typedef'd as in |int|. TODO(palmer): It |
| 452 // should be a |size_t|, or at least unsigned. | 445 // should be a |size_t|, or at least unsigned. |
| 453 if (nCopyLen == 0 || nCopyLen < 0) { | 446 if (nCopyLen == 0 || nCopyLen < 0) { |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 fraction %= scale; | 1072 fraction %= scale; |
| 1080 scale /= 10; | 1073 scale /= 10; |
| 1081 } | 1074 } |
| 1082 return buf_size; | 1075 return buf_size; |
| 1083 } | 1076 } |
| 1084 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { | 1077 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { |
| 1085 FX_CHAR buf[32]; | 1078 FX_CHAR buf[32]; |
| 1086 FX_STRSIZE len = FX_ftoa(d, buf); | 1079 FX_STRSIZE len = FX_ftoa(d, buf); |
| 1087 return CFX_ByteString(buf, len); | 1080 return CFX_ByteString(buf, len); |
| 1088 } | 1081 } |
| OLD | NEW |