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 CORE_FXCRT_INCLUDE_FX_STRING_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_STRING_H_ |
8 #define CORE_FXCRT_INCLUDE_FX_STRING_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_STRING_H_ |
9 | 9 |
10 #include <stdint.h> // For intptr_t. | 10 #include <stdint.h> // For intptr_t. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 | 183 |
184 // Implicit conversion to uint8_t* -- deprecated. | 184 // Implicit conversion to uint8_t* -- deprecated. |
185 operator const uint8_t*() const { | 185 operator const uint8_t*() const { |
186 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) | 186 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) |
187 : nullptr; | 187 : nullptr; |
188 } | 188 } |
189 | 189 |
190 // Explicit conversion to CFX_ByteStringC. | 190 // Explicit conversion to CFX_ByteStringC. |
191 // Note: |this| must outlive the use of the result. | 191 // Note: |this| must outlive the use of the result. |
192 CFX_ByteStringC AsByteStringC() const { | 192 CFX_ByteStringC AsStringC() const { |
193 return CFX_ByteStringC(raw_str(), GetLength()); | 193 return CFX_ByteStringC(raw_str(), GetLength()); |
194 } | 194 } |
195 | 195 |
196 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } | 196 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } |
197 bool IsEmpty() const { return !GetLength(); } | 197 bool IsEmpty() const { return !GetLength(); } |
198 | 198 |
199 int Compare(const CFX_ByteStringC& str) const; | 199 int Compare(const CFX_ByteStringC& str) const; |
200 bool EqualNoCase(const CFX_ByteStringC& str) const; | 200 bool EqualNoCase(const CFX_ByteStringC& str) const; |
201 | 201 |
202 bool operator==(const char* ptr) const; | 202 bool operator==(const char* ptr) const; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 return CFX_ByteString(str1, str2); | 329 return CFX_ByteString(str1, str2); |
330 } | 330 } |
331 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, FX_CHAR ch) { | 331 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, FX_CHAR ch) { |
332 return CFX_ByteString(str1, CFX_ByteStringC(ch)); | 332 return CFX_ByteString(str1, CFX_ByteStringC(ch)); |
333 } | 333 } |
334 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteStringC& str2) { | 334 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteStringC& str2) { |
335 return CFX_ByteString(ch, str2); | 335 return CFX_ByteString(ch, str2); |
336 } | 336 } |
337 inline CFX_ByteString operator+(const CFX_ByteString& str1, | 337 inline CFX_ByteString operator+(const CFX_ByteString& str1, |
338 const CFX_ByteString& str2) { | 338 const CFX_ByteString& str2) { |
339 return CFX_ByteString(str1.AsByteStringC(), str2.AsByteStringC()); | 339 return CFX_ByteString(str1.AsStringC(), str2.AsStringC()); |
340 } | 340 } |
341 inline CFX_ByteString operator+(const CFX_ByteString& str1, FX_CHAR ch) { | 341 inline CFX_ByteString operator+(const CFX_ByteString& str1, FX_CHAR ch) { |
342 return CFX_ByteString(str1.AsByteStringC(), CFX_ByteStringC(ch)); | 342 return CFX_ByteString(str1.AsStringC(), CFX_ByteStringC(ch)); |
343 } | 343 } |
344 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteString& str2) { | 344 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteString& str2) { |
345 return CFX_ByteString(ch, str2.AsByteStringC()); | 345 return CFX_ByteString(ch, str2.AsStringC()); |
346 } | 346 } |
347 inline CFX_ByteString operator+(const CFX_ByteString& str1, | 347 inline CFX_ByteString operator+(const CFX_ByteString& str1, |
348 const FX_CHAR* str2) { | 348 const FX_CHAR* str2) { |
349 return CFX_ByteString(str1.AsByteStringC(), str2); | 349 return CFX_ByteString(str1.AsStringC(), str2); |
350 } | 350 } |
351 inline CFX_ByteString operator+(const FX_CHAR* str1, | 351 inline CFX_ByteString operator+(const FX_CHAR* str1, |
352 const CFX_ByteString& str2) { | 352 const CFX_ByteString& str2) { |
353 return CFX_ByteString(str1, str2.AsByteStringC()); | 353 return CFX_ByteString(str1, str2.AsStringC()); |
354 } | 354 } |
355 inline CFX_ByteString operator+(const CFX_ByteString& str1, | 355 inline CFX_ByteString operator+(const CFX_ByteString& str1, |
356 const CFX_ByteStringC& str2) { | 356 const CFX_ByteStringC& str2) { |
357 return CFX_ByteString(str1.AsByteStringC(), str2); | 357 return CFX_ByteString(str1.AsStringC(), str2); |
358 } | 358 } |
359 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, | 359 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, |
360 const CFX_ByteString& str2) { | 360 const CFX_ByteString& str2) { |
361 return CFX_ByteString(str1, str2.AsByteStringC()); | 361 return CFX_ByteString(str1, str2.AsStringC()); |
362 } | 362 } |
363 | 363 |
364 class CFX_WideStringC { | 364 class CFX_WideStringC { |
365 public: | 365 public: |
366 typedef FX_WCHAR value_type; | 366 typedef FX_WCHAR value_type; |
367 | 367 |
368 CFX_WideStringC() { | 368 CFX_WideStringC() { |
369 m_Ptr = NULL; | 369 m_Ptr = NULL; |
370 m_Length = 0; | 370 m_Length = 0; |
371 } | 371 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 // Explicit conversion to C-style wide string. | 509 // Explicit conversion to C-style wide string. |
510 // Note: |this| must outlive the use of the result. | 510 // Note: |this| must outlive the use of the result. |
511 const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; } | 511 const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; } |
512 | 512 |
513 // Implicit conversion to C-style wide string -- deprecated. | 513 // Implicit conversion to C-style wide string -- deprecated. |
514 // Note: |this| must outlive the use of the result. | 514 // Note: |this| must outlive the use of the result. |
515 operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; } | 515 operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; } |
516 | 516 |
517 // Explicit conversion to CFX_WideStringC. | 517 // Explicit conversion to CFX_WideStringC. |
518 // Note: |this| must outlive the use of the result. | 518 // Note: |this| must outlive the use of the result. |
519 CFX_WideStringC AsWideStringC() const { | 519 CFX_WideStringC AsStringC() const { |
520 return CFX_WideStringC(c_str(), GetLength()); | 520 return CFX_WideStringC(c_str(), GetLength()); |
521 } | 521 } |
522 | 522 |
523 // Deprecated -- use clear(). | 523 // Deprecated -- use clear(). |
524 void Empty() { m_pData.Reset(); } | 524 void Empty() { m_pData.Reset(); } |
525 void clear() { m_pData.Reset(); } | 525 void clear() { m_pData.Reset(); } |
526 | 526 |
527 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } | 527 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } |
528 bool IsEmpty() const { return !GetLength(); } | 528 bool IsEmpty() const { return !GetLength(); } |
529 | 529 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 return CFX_WideString(str1, str2); | 638 return CFX_WideString(str1, str2); |
639 } | 639 } |
640 inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) { | 640 inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) { |
641 return CFX_WideString(str1, CFX_WideStringC(ch)); | 641 return CFX_WideString(str1, CFX_WideStringC(ch)); |
642 } | 642 } |
643 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideStringC& str2) { | 643 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideStringC& str2) { |
644 return CFX_WideString(ch, str2); | 644 return CFX_WideString(ch, str2); |
645 } | 645 } |
646 inline CFX_WideString operator+(const CFX_WideString& str1, | 646 inline CFX_WideString operator+(const CFX_WideString& str1, |
647 const CFX_WideString& str2) { | 647 const CFX_WideString& str2) { |
648 return CFX_WideString(str1.AsWideStringC(), str2.AsWideStringC()); | 648 return CFX_WideString(str1.AsStringC(), str2.AsStringC()); |
649 } | 649 } |
650 inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) { | 650 inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) { |
651 return CFX_WideString(str1.AsWideStringC(), CFX_WideStringC(ch)); | 651 return CFX_WideString(str1.AsStringC(), CFX_WideStringC(ch)); |
652 } | 652 } |
653 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) { | 653 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) { |
654 return CFX_WideString(ch, str2.AsWideStringC()); | 654 return CFX_WideString(ch, str2.AsStringC()); |
655 } | 655 } |
656 inline CFX_WideString operator+(const CFX_WideString& str1, | 656 inline CFX_WideString operator+(const CFX_WideString& str1, |
657 const FX_WCHAR* str2) { | 657 const FX_WCHAR* str2) { |
658 return CFX_WideString(str1.AsWideStringC(), str2); | 658 return CFX_WideString(str1.AsStringC(), str2); |
659 } | 659 } |
660 inline CFX_WideString operator+(const FX_WCHAR* str1, | 660 inline CFX_WideString operator+(const FX_WCHAR* str1, |
661 const CFX_WideString& str2) { | 661 const CFX_WideString& str2) { |
662 return CFX_WideString(str1, str2.AsWideStringC()); | 662 return CFX_WideString(str1, str2.AsStringC()); |
663 } | 663 } |
664 inline CFX_WideString operator+(const CFX_WideString& str1, | 664 inline CFX_WideString operator+(const CFX_WideString& str1, |
665 const CFX_WideStringC& str2) { | 665 const CFX_WideStringC& str2) { |
666 return CFX_WideString(str1.AsWideStringC(), str2); | 666 return CFX_WideString(str1.AsStringC(), str2); |
667 } | 667 } |
668 inline CFX_WideString operator+(const CFX_WideStringC& str1, | 668 inline CFX_WideString operator+(const CFX_WideStringC& str1, |
669 const CFX_WideString& str2) { | 669 const CFX_WideString& str2) { |
670 return CFX_WideString(str1, str2.AsWideStringC()); | 670 return CFX_WideString(str1, str2.AsStringC()); |
671 } | 671 } |
672 inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) { | 672 inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) { |
673 return rhs == lhs; | 673 return rhs == lhs; |
674 } | 674 } |
675 inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { | 675 inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { |
676 return rhs == lhs; | 676 return rhs == lhs; |
677 } | 677 } |
678 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { | 678 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { |
679 return rhs != lhs; | 679 return rhs != lhs; |
680 } | 680 } |
(...skipping 10 matching lines...) Expand all Loading... |
691 } | 691 } |
692 | 692 |
693 FX_FLOAT FX_atof(const CFX_ByteStringC& str); | 693 FX_FLOAT FX_atof(const CFX_ByteStringC& str); |
694 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { | 694 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { |
695 return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); | 695 return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); |
696 } | 696 } |
697 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); | 697 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); |
698 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 698 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
699 | 699 |
700 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ | 700 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ |
OLD | NEW |