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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 == NULL || 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 != NULL) { | 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 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 == NULL || 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 != NULL) { | 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; |
(...skipping 375 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 |