| 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 <algorithm> |
| 11 |
| 10 #include "fx_memory.h" | 12 #include "fx_memory.h" |
| 11 | 13 |
| 12 class CFX_ByteStringC; | 14 class CFX_ByteStringC; |
| 13 class CFX_ByteString; | 15 class CFX_ByteString; |
| 14 class CFX_WideStringC; | 16 class CFX_WideStringC; |
| 15 class CFX_WideString; | 17 class CFX_WideString; |
| 16 struct CFX_CharMap; | 18 struct CFX_CharMap; |
| 17 class CFX_BinaryBuf; | 19 class CFX_BinaryBuf; |
| 18 typedef int FX_STRSIZE; | 20 typedef int FX_STRSIZE; |
| 19 class CFX_ByteStringL; | 21 class CFX_ByteStringL; |
| 20 class CFX_WideStringL; | 22 class CFX_WideStringL; |
| 21 | 23 |
| 22 // An immutable string with caller-provided storage which must outlive the | 24 // An immutable string with caller-provided storage which must outlive the |
| 23 // string itself. | 25 // string itself. |
| 24 class CFX_ByteStringC | 26 class CFX_ByteStringC |
| 25 { | 27 { |
| 26 public: | 28 public: |
| 27 typedef FX_CHAR value_type; | 29 typedef FX_CHAR value_type; |
| 28 | 30 |
| 29 CFX_ByteStringC() | 31 CFX_ByteStringC() |
| 30 { | 32 { |
| 31 m_Ptr = NULL; | 33 m_Ptr = NULL; |
| 32 m_Length = 0; | 34 m_Length = 0; |
| 33 } | 35 } |
| 34 | 36 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 95 |
| 94 bool operator == (const CFX_ByteStringC& str) const | 96 bool operator == (const CFX_ByteStringC& str) const |
| 95 { | 97 { |
| 96 return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L
ength) == 0; | 98 return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L
ength) == 0; |
| 97 } | 99 } |
| 98 | 100 |
| 99 bool operator != (const CFX_ByteStringC& str) const | 101 bool operator != (const CFX_ByteStringC& str) const |
| 100 { | 102 { |
| 101 return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L
ength) != 0; | 103 return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L
ength) != 0; |
| 102 } | 104 } |
| 103 #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4)) | |
| 104 | 105 |
| 105 FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; | 106 FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; |
| 106 | 107 |
| 107 FX_LPCBYTE GetPtr() const | 108 FX_LPCBYTE GetPtr() const |
| 108 { | 109 { |
| 109 return m_Ptr; | 110 return m_Ptr; |
| 110 } | 111 } |
| 111 | 112 |
| 112 FX_LPCSTR GetCStr() const | 113 FX_LPCSTR GetCStr() const |
| 113 { | 114 { |
| 114 return (FX_LPCSTR)m_Ptr; | 115 return (FX_LPCSTR)m_Ptr; |
| 115 } | 116 } |
| 116 | 117 |
| 117 FX_STRSIZE GetLength() const | 118 FX_STRSIZE GetLength() const |
| 118 { | 119 { |
| 119 return m_Length; | 120 return m_Length; |
| 120 } | 121 } |
| 121 | 122 |
| 122 bool IsEmpty() const | 123 bool IsEmpty() const |
| 123 { | 124 { |
| 124 return m_Length == 0; | 125 return m_Length == 0; |
| 125 } | 126 } |
| 126 | 127 |
| 127 operator FX_LPCBYTE() const | |
| 128 { | |
| 129 return m_Ptr; | |
| 130 } | |
| 131 | |
| 132 FX_BYTE GetAt(FX_STRSIZE index) const | 128 FX_BYTE GetAt(FX_STRSIZE index) const |
| 133 { | 129 { |
| 134 return m_Ptr[index]; | 130 return m_Ptr[index]; |
| 135 } | 131 } |
| 136 | 132 |
| 137 CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const | 133 CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const |
| 138 { | 134 { |
| 139 if (index < 0) { | 135 if (index < 0) { |
| 140 index = 0; | 136 index = 0; |
| 141 } | 137 } |
| 142 if (index > m_Length) { | 138 if (index > m_Length) { |
| 143 return CFX_ByteStringC(); | 139 return CFX_ByteStringC(); |
| 144 } | 140 } |
| 145 if (count < 0 || count > m_Length - index) { | 141 if (count < 0 || count > m_Length - index) { |
| 146 count = m_Length - index; | 142 count = m_Length - index; |
| 147 } | 143 } |
| 148 return CFX_ByteStringC(m_Ptr + index, count); | 144 return CFX_ByteStringC(m_Ptr + index, count); |
| 149 } | 145 } |
| 146 |
| 147 const FX_BYTE& operator[] (size_t index) const |
| 148 { |
| 149 return m_Ptr[index]; |
| 150 } |
| 151 |
| 152 bool operator< (const CFX_ByteStringC& that) const |
| 153 { |
| 154 int result = memcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length)
); |
| 155 return result < 0 || (result == 0 && m_Length < that.m_Length); |
| 156 } |
| 157 |
| 150 protected: | 158 protected: |
| 159 FX_LPCBYTE m_Ptr; |
| 160 FX_STRSIZE m_Length; |
| 151 | 161 |
| 152 FX_LPCBYTE m_Ptr; | |
| 153 | |
| 154 FX_STRSIZE m_Length; | |
| 155 private: | 162 private: |
| 156 | |
| 157 void* operator new (size_t) throw() | 163 void* operator new (size_t) throw() |
| 158 { | 164 { |
| 159 return NULL; | 165 return NULL; |
| 160 } | 166 } |
| 161 }; | 167 }; |
| 162 typedef const CFX_ByteStringC& FX_BSTR; | 168 typedef const CFX_ByteStringC& FX_BSTR; |
| 163 #define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1) | 169 #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)) |
| 164 struct CFX_StringData { | 171 struct CFX_StringData { |
| 165 | 172 |
| 166 long m_nRefs; | 173 long m_nRefs; |
| 167 | 174 |
| 168 FX_STRSIZE m_nDataLength; | 175 FX_STRSIZE m_nDataLength; |
| 169 | 176 |
| 170 FX_STRSIZE m_nAllocLength; | 177 FX_STRSIZE m_nAllocLength; |
| 171 | 178 |
| 172 FX_CHAR m_String[1]; | 179 FX_CHAR m_String[1]; |
| 173 }; | 180 }; |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); | 818 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); |
| 812 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) | 819 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) |
| 813 { | 820 { |
| 814 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 821 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); |
| 815 } | 822 } |
| 816 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) | 823 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) |
| 817 { | 824 { |
| 818 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 825 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
| 819 } | 826 } |
| 820 #endif | 827 #endif |
| OLD | NEW |