| 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 #ifndef _FX_STRING_H_ | 7 #ifndef _FX_STRING_H_ |
| 8 #define _FX_STRING_H_ | 8 #define _FX_STRING_H_ |
| 9 | 9 |
| 10 #include <stdint.h> // For intptr_t. |
| 10 #include <algorithm> | 11 #include <algorithm> |
| 11 | 12 |
| 12 #include "fx_memory.h" | 13 #include "fx_memory.h" |
| 13 | 14 |
| 14 class CFX_ByteStringC; | 15 class CFX_ByteStringC; |
| 15 class CFX_ByteString; | 16 class CFX_ByteString; |
| 16 class CFX_WideStringC; | 17 class CFX_WideStringC; |
| 17 class CFX_WideString; | 18 class CFX_WideString; |
| 18 struct CFX_CharMap; | 19 struct CFX_CharMap; |
| 19 class CFX_BinaryBuf; | 20 class CFX_BinaryBuf; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 162 |
| 162 private: | 163 private: |
| 163 void* operator new (size_t) throw() | 164 void* operator new (size_t) throw() |
| 164 { | 165 { |
| 165 return NULL; | 166 return NULL; |
| 166 } | 167 } |
| 167 }; | 168 }; |
| 168 typedef const CFX_ByteStringC& FX_BSTR; | 169 typedef const CFX_ByteStringC& FX_BSTR; |
| 169 #define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1) | 170 #define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1) |
| 170 #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4)) | 171 #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4)) |
| 172 |
| 173 // To ensure ref counts do not overflow, consider the worst possible case: |
| 174 // the entire address space contains nothing but pointers to this object. |
| 175 // Since the count increments with each new pointer, the largest value is |
| 176 // the number of pointers that can fit into the address space. The size of |
| 177 // the address space itself is a good upper bound on it; we need not go |
| 178 // larger. |
| 171 struct CFX_StringData { | 179 struct CFX_StringData { |
| 172 | 180 intptr_t» m_nRefs; // Would prefer ssize_t, but no windows support. |
| 173 long» » m_nRefs; | |
| 174 | |
| 175 FX_STRSIZE m_nDataLength; | 181 FX_STRSIZE m_nDataLength; |
| 176 | |
| 177 FX_STRSIZE m_nAllocLength; | 182 FX_STRSIZE m_nAllocLength; |
| 178 | |
| 179 FX_CHAR m_String[1]; | 183 FX_CHAR m_String[1]; |
| 180 }; | 184 }; |
| 181 class CFX_ByteString | 185 class CFX_ByteString |
| 182 { | 186 { |
| 183 public: | 187 public: |
| 184 typedef FX_CHAR value_type; | 188 typedef FX_CHAR value_type; |
| 185 | 189 |
| 186 CFX_ByteString() | 190 CFX_ByteString() |
| 187 { | 191 { |
| 188 m_pData = NULL; | 192 m_pData = NULL; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 583 |
| 580 private: | 584 private: |
| 581 void* operator new (size_t) throw() | 585 void* operator new (size_t) throw() |
| 582 { | 586 { |
| 583 return NULL; | 587 return NULL; |
| 584 } | 588 } |
| 585 }; | 589 }; |
| 586 typedef const CFX_WideStringC& FX_WSTR; | 590 typedef const CFX_WideStringC& FX_WSTR; |
| 587 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) | 591 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) |
| 588 struct CFX_StringDataW { | 592 struct CFX_StringDataW { |
| 589 | 593 intptr_t» m_nRefs; // Would prefer ssize_t, but no windows support. |
| 590 long» » m_nRefs; | |
| 591 | |
| 592 FX_STRSIZE m_nDataLength; | 594 FX_STRSIZE m_nDataLength; |
| 593 | |
| 594 FX_STRSIZE m_nAllocLength; | 595 FX_STRSIZE m_nAllocLength; |
| 595 | |
| 596 FX_WCHAR m_String[1]; | 596 FX_WCHAR m_String[1]; |
| 597 }; | 597 }; |
| 598 class CFX_WideString | 598 class CFX_WideString |
| 599 { | 599 { |
| 600 public: | 600 public: |
| 601 typedef FX_WCHAR value_type; | 601 typedef FX_WCHAR value_type; |
| 602 | 602 |
| 603 CFX_WideString() | 603 CFX_WideString() |
| 604 { | 604 { |
| 605 m_pData = NULL; | 605 m_pData = NULL; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); | 835 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); |
| 836 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) | 836 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) |
| 837 { | 837 { |
| 838 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 838 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); |
| 839 } | 839 } |
| 840 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) | 840 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) |
| 841 { | 841 { |
| 842 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 842 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
| 843 } | 843 } |
| 844 #endif | 844 #endif |
| OLD | NEW |