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 <stdint.h> // For intptr_t. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 CFX_ByteStringC& operator = (const CFX_ByteStringC& src) | 88 CFX_ByteStringC& operator = (const CFX_ByteStringC& src) |
89 { | 89 { |
90 m_Ptr = src.m_Ptr; | 90 m_Ptr = src.m_Ptr; |
91 m_Length = src.m_Length; | 91 m_Length = src.m_Length; |
92 return *this; | 92 return *this; |
93 } | 93 } |
94 | 94 |
95 CFX_ByteStringC& operator = (const CFX_ByteString& src); | 95 CFX_ByteStringC& operator = (const CFX_ByteString& src); |
96 | 96 |
97 bool» » » operator == (const CFX_ByteStringC& str) const | 97 bool operator== (const char* ptr) const { |
98 { | 98 return strlen(ptr) == m_Length && |
99 return »str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L
ength) == 0; | 99 FXSYS_memcmp32(ptr, m_Ptr, m_Length) == 0; |
100 } | 100 } |
101 | 101 bool operator== (const CFX_ByteStringC& other) const { |
102 bool» » » operator != (const CFX_ByteStringC& str) const | 102 return other.m_Length == m_Length && |
103 { | 103 FXSYS_memcmp32(other.m_Ptr, m_Ptr, m_Length) == 0; |
104 return »str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L
ength) != 0; | 104 } |
| 105 bool operator!= (const char* ptr) const { return !(*this == ptr); } |
| 106 bool operator!= (const CFX_ByteStringC& other) const { |
| 107 return !(*this == other); |
105 } | 108 } |
106 | 109 |
107 FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; | 110 FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; |
108 | 111 |
109 FX_LPCBYTE GetPtr() const | 112 FX_LPCBYTE GetPtr() const |
110 { | 113 { |
111 return m_Ptr; | 114 return m_Ptr; |
112 } | 115 } |
113 | 116 |
114 FX_LPCSTR GetCStr() const | 117 FX_LPCSTR GetCStr() const |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 protected: | 162 protected: |
160 FX_LPCBYTE m_Ptr; | 163 FX_LPCBYTE m_Ptr; |
161 FX_STRSIZE m_Length; | 164 FX_STRSIZE m_Length; |
162 | 165 |
163 private: | 166 private: |
164 void* operator new (size_t) throw() | 167 void* operator new (size_t) throw() |
165 { | 168 { |
166 return NULL; | 169 return NULL; |
167 } | 170 } |
168 }; | 171 }; |
| 172 inline bool operator== (const char* lhs, const CFX_ByteStringC& rhs) { |
| 173 return rhs == lhs; |
| 174 } |
| 175 inline bool operator!= (const char* lhs, const CFX_ByteStringC& rhs) { |
| 176 return rhs != lhs; |
| 177 } |
169 typedef const CFX_ByteStringC& FX_BSTR; | 178 typedef const CFX_ByteStringC& FX_BSTR; |
170 #define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1) | 179 #define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1) |
171 #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4)) | 180 #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4)) |
172 | 181 |
173 // To ensure ref counts do not overflow, consider the worst possible case: | 182 // To ensure ref counts do not overflow, consider the worst possible case: |
174 // the entire address space contains nothing but pointers to this object. | 183 // the entire address space contains nothing but pointers to this object. |
175 // Since the count increments with each new pointer, the largest value is | 184 // 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 | 185 // 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 | 186 // the address space itself is a good upper bound on it; we need not go |
178 // larger. | 187 // larger. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 245 } |
237 | 246 |
238 bool IsEmpty() const | 247 bool IsEmpty() const |
239 { | 248 { |
240 return !GetLength(); | 249 return !GetLength(); |
241 } | 250 } |
242 | 251 |
243 int Compare(FX_BSTR str) const; | 252 int Compare(FX_BSTR str) const; |
244 | 253 |
245 | 254 |
246 bool» » » » » Equal(FX_BSTR str) const; | 255 bool Equal(const char* ptr) const; |
| 256 bool Equal(const CFX_ByteStringC& str) const; |
| 257 bool Equal(const CFX_ByteString& other) const; |
247 | 258 |
| 259 bool EqualNoCase(FX_BSTR str) const; |
248 | 260 |
249 bool» » » » » EqualNoCase(FX_BSTR str) const; | 261 bool operator== (const char* ptr) const { return Equal(ptr); } |
| 262 bool operator== (const CFX_ByteStringC& str) const { return Equal(str); } |
| 263 bool operator== (const CFX_ByteString& other) const { return Equal(other); } |
250 | 264 |
251 bool» » » » » operator == (FX_LPCSTR str) cons
t | 265 bool operator!= (const char* ptr) const { return !(*this == ptr); } |
252 { | 266 bool operator!= (const CFX_ByteStringC& str) const { |
253 return Equal(str); | 267 return !(*this == str); |
254 } | 268 } |
255 | 269 bool operator!= (const CFX_ByteString& other) const { |
256 bool» » » » » operator == (FX_BSTR str) const | 270 return !(*this == other); |
257 { | |
258 return Equal(str); | |
259 } | |
260 | |
261 bool» » » » » operator == (const CFX_ByteStrin
g& str) const; | |
262 | |
263 bool» » » » » operator != (FX_LPCSTR str) cons
t | |
264 { | |
265 return !Equal(str); | |
266 } | |
267 | |
268 bool» » » » » operator != (FX_BSTR str) const | |
269 { | |
270 return !Equal(str); | |
271 } | |
272 | |
273 bool» » » » » operator != (const CFX_ByteStrin
g& str) const | |
274 { | |
275 return !operator==(str); | |
276 } | 271 } |
277 | 272 |
278 bool operator< (const CFX_ByteString& str) const | 273 bool operator< (const CFX_ByteString& str) const |
279 { | 274 { |
280 int result = FXSYS_memcmp32(c_str(), str.c_str(), std::min(GetLength(),
str.GetLength())); | 275 int result = FXSYS_memcmp32(c_str(), str.c_str(), std::min(GetLength(),
str.GetLength())); |
281 return result < 0 || (result == 0 && GetLength() < str.GetLength()); | 276 return result < 0 || (result == 0 && GetLength() < str.GetLength()); |
282 } | 277 } |
283 | 278 |
284 void Empty(); | 279 void Empty(); |
285 | 280 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 m_Ptr = (FX_LPCBYTE)src; | 386 m_Ptr = (FX_LPCBYTE)src; |
392 m_Length = src.GetLength(); | 387 m_Length = src.GetLength(); |
393 } | 388 } |
394 inline CFX_ByteStringC& CFX_ByteStringC::operator = (const CFX_ByteString& src) | 389 inline CFX_ByteStringC& CFX_ByteStringC::operator = (const CFX_ByteString& src) |
395 { | 390 { |
396 m_Ptr = (FX_LPCBYTE)src; | 391 m_Ptr = (FX_LPCBYTE)src; |
397 m_Length = src.GetLength(); | 392 m_Length = src.GetLength(); |
398 return *this; | 393 return *this; |
399 } | 394 } |
400 | 395 |
| 396 inline bool operator== (const char* lhs, const CFX_ByteString& rhs) { |
| 397 return rhs == lhs; |
| 398 } |
| 399 inline bool operator== (const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { |
| 400 return rhs == lhs; |
| 401 } |
| 402 inline bool operator!= (const char* lhs, const CFX_ByteString& rhs) { |
| 403 return rhs != lhs; |
| 404 } |
| 405 inline bool operator!= (const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { |
| 406 return rhs != lhs; |
| 407 } |
| 408 |
401 inline CFX_ByteString operator + (FX_BSTR str1, FX_BSTR str2) | 409 inline CFX_ByteString operator + (FX_BSTR str1, FX_BSTR str2) |
402 { | 410 { |
403 return CFX_ByteString(str1, str2); | 411 return CFX_ByteString(str1, str2); |
404 } | 412 } |
405 inline CFX_ByteString operator + (FX_BSTR str1, FX_LPCSTR str2) | 413 inline CFX_ByteString operator + (FX_BSTR str1, FX_LPCSTR str2) |
406 { | 414 { |
407 return CFX_ByteString(str1, str2); | 415 return CFX_ByteString(str1, str2); |
408 } | 416 } |
409 inline CFX_ByteString operator + (FX_LPCSTR str1, FX_BSTR str2) | 417 inline CFX_ByteString operator + (FX_LPCSTR str1, FX_BSTR str2) |
410 { | 418 { |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); | 849 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); |
842 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) | 850 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) |
843 { | 851 { |
844 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 852 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); |
845 } | 853 } |
846 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) | 854 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) |
847 { | 855 { |
848 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 856 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
849 } | 857 } |
850 #endif | 858 #endif |
OLD | NEW |