| 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) { | 424 CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) { |
| 425 m_Ptr = ptr; | 425 m_Ptr = ptr; |
| 426 m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len; | 426 m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len; |
| 427 } | 427 } |
| 428 | 428 |
| 429 CFX_WideStringC(const CFX_WideStringC& src) { | 429 CFX_WideStringC(const CFX_WideStringC& src) { |
| 430 m_Ptr = src.m_Ptr; | 430 m_Ptr = src.m_Ptr; |
| 431 m_Length = src.m_Length; | 431 m_Length = src.m_Length; |
| 432 } | 432 } |
| 433 | 433 |
| 434 CFX_WideStringC(const CFX_WideString& src); | |
| 435 | |
| 436 CFX_WideStringC& operator=(const FX_WCHAR* src) { | 434 CFX_WideStringC& operator=(const FX_WCHAR* src) { |
| 437 m_Ptr = src; | 435 m_Ptr = src; |
| 438 m_Length = FXSYS_wcslen(src); | 436 m_Length = FXSYS_wcslen(src); |
| 439 return *this; | 437 return *this; |
| 440 } | 438 } |
| 441 | 439 |
| 442 CFX_WideStringC& operator=(const CFX_WideStringC& src) { | 440 CFX_WideStringC& operator=(const CFX_WideStringC& src) { |
| 443 m_Ptr = src.m_Ptr; | 441 m_Ptr = src.m_Ptr; |
| 444 m_Length = src.m_Length; | 442 m_Length = src.m_Length; |
| 445 return *this; | 443 return *this; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 static CFX_WideString FromLocal(const CFX_ByteString& str); | 548 static CFX_WideString FromLocal(const CFX_ByteString& str); |
| 551 static CFX_WideString FromCodePage(const CFX_ByteString& str, | 549 static CFX_WideString FromCodePage(const CFX_ByteString& str, |
| 552 uint16_t codepage); | 550 uint16_t codepage); |
| 553 | 551 |
| 554 static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len); | 552 static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len); |
| 555 static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); | 553 static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); |
| 556 | 554 |
| 557 static FX_STRSIZE WStringLength(const unsigned short* str); | 555 static FX_STRSIZE WStringLength(const unsigned short* str); |
| 558 | 556 |
| 559 // Explicit conversion to C-style wide string. | 557 // Explicit conversion to C-style wide string. |
| 558 // Note: |this| must outlive the use of the result. |
| 560 const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; } | 559 const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; } |
| 561 | 560 |
| 562 // Implicit conversion to C-style wide string -- deprecated. | 561 // Implicit conversion to C-style wide string -- deprecated. |
| 562 // Note: |this| must outlive the use of the result. |
| 563 operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; } | 563 operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; } |
| 564 | 564 |
| 565 // Explicit conversion to CFX_WideStringC. |
| 566 // Note: |this| must outlive the use of the result. |
| 567 CFX_WideStringC AsWideStringC() const { |
| 568 return CFX_WideStringC(c_str(), GetLength()); |
| 569 } |
| 570 |
| 565 void Empty(); | 571 void Empty(); |
| 566 | |
| 567 bool IsEmpty() const { return !GetLength(); } | 572 bool IsEmpty() const { return !GetLength(); } |
| 568 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } | 573 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } |
| 569 | 574 |
| 570 const CFX_WideString& operator=(const FX_WCHAR* str); | 575 const CFX_WideString& operator=(const FX_WCHAR* str); |
| 571 const CFX_WideString& operator=(const CFX_WideString& stringSrc); | 576 const CFX_WideString& operator=(const CFX_WideString& stringSrc); |
| 572 const CFX_WideString& operator=(const CFX_WideStringC& stringSrc); | 577 const CFX_WideString& operator=(const CFX_WideStringC& stringSrc); |
| 573 | 578 |
| 574 const CFX_WideString& operator+=(const FX_WCHAR* str); | 579 const CFX_WideString& operator+=(const FX_WCHAR* str); |
| 575 const CFX_WideString& operator+=(FX_WCHAR ch); | 580 const CFX_WideString& operator+=(FX_WCHAR ch); |
| 576 const CFX_WideString& operator+=(const CFX_WideString& str); | 581 const CFX_WideString& operator+=(const CFX_WideString& str); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 FX_STRSIZE nSrc2Len, | 683 FX_STRSIZE nSrc2Len, |
| 679 const FX_WCHAR* lpszSrc2Data); | 684 const FX_WCHAR* lpszSrc2Data); |
| 680 void AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData); | 685 void AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData); |
| 681 void AllocCopy(CFX_WideString& dest, | 686 void AllocCopy(CFX_WideString& dest, |
| 682 FX_STRSIZE nCopyLen, | 687 FX_STRSIZE nCopyLen, |
| 683 FX_STRSIZE nCopyIndex) const; | 688 FX_STRSIZE nCopyIndex) const; |
| 684 | 689 |
| 685 StringData* m_pData; | 690 StringData* m_pData; |
| 686 friend class fxcrt_WideStringConcatInPlace_Test; | 691 friend class fxcrt_WideStringConcatInPlace_Test; |
| 687 }; | 692 }; |
| 688 inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src) { | 693 |
| 689 m_Ptr = src.c_str(); | |
| 690 m_Length = src.GetLength(); | |
| 691 } | |
| 692 inline CFX_WideStringC& CFX_WideStringC::operator=(const CFX_WideString& src) { | 694 inline CFX_WideStringC& CFX_WideStringC::operator=(const CFX_WideString& src) { |
| 693 m_Ptr = src.c_str(); | 695 m_Ptr = src.c_str(); |
| 694 m_Length = src.GetLength(); | 696 m_Length = src.GetLength(); |
| 695 return *this; | 697 return *this; |
| 696 } | 698 } |
| 697 | 699 |
| 698 inline CFX_WideString operator+(const CFX_WideStringC& str1, | 700 inline CFX_WideString operator+(const CFX_WideStringC& str1, |
| 699 const CFX_WideStringC& str2) { | 701 const CFX_WideStringC& str2) { |
| 700 return CFX_WideString(str1, str2); | 702 return CFX_WideString(str1, str2); |
| 701 } | 703 } |
| 702 inline CFX_WideString operator+(const CFX_WideStringC& str1, | 704 inline CFX_WideString operator+(const CFX_WideStringC& str1, |
| 703 const FX_WCHAR* str2) { | 705 const FX_WCHAR* str2) { |
| 704 return CFX_WideString(str1, str2); | 706 return CFX_WideString(str1, str2); |
| 705 } | 707 } |
| 706 inline CFX_WideString operator+(const FX_WCHAR* str1, | 708 inline CFX_WideString operator+(const FX_WCHAR* str1, |
| 707 const CFX_WideStringC& str2) { | 709 const CFX_WideStringC& str2) { |
| 708 return CFX_WideString(str1, str2); | 710 return CFX_WideString(str1, str2); |
| 709 } | 711 } |
| 710 inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) { | 712 inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) { |
| 711 return CFX_WideString(str1, CFX_WideStringC(ch)); | 713 return CFX_WideString(str1, CFX_WideStringC(ch)); |
| 712 } | 714 } |
| 713 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideStringC& str2) { | 715 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideStringC& str2) { |
| 714 return CFX_WideString(ch, str2); | 716 return CFX_WideString(ch, str2); |
| 715 } | 717 } |
| 716 inline CFX_WideString operator+(const CFX_WideString& str1, | 718 inline CFX_WideString operator+(const CFX_WideString& str1, |
| 717 const CFX_WideString& str2) { | 719 const CFX_WideString& str2) { |
| 718 return CFX_WideString(str1, str2); | 720 return CFX_WideString(str1.AsWideStringC(), str2.AsWideStringC()); |
| 719 } | 721 } |
| 720 inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) { | 722 inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) { |
| 721 return CFX_WideString(str1, CFX_WideStringC(ch)); | 723 return CFX_WideString(str1.AsWideStringC(), CFX_WideStringC(ch)); |
| 722 } | 724 } |
| 723 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) { | 725 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) { |
| 724 return CFX_WideString(ch, str2); | 726 return CFX_WideString(ch, str2.AsWideStringC()); |
| 725 } | 727 } |
| 726 inline CFX_WideString operator+(const CFX_WideString& str1, | 728 inline CFX_WideString operator+(const CFX_WideString& str1, |
| 727 const FX_WCHAR* str2) { | 729 const FX_WCHAR* str2) { |
| 728 return CFX_WideString(str1, str2); | 730 return CFX_WideString(str1.AsWideStringC(), str2); |
| 729 } | 731 } |
| 730 inline CFX_WideString operator+(const FX_WCHAR* str1, | 732 inline CFX_WideString operator+(const FX_WCHAR* str1, |
| 731 const CFX_WideString& str2) { | 733 const CFX_WideString& str2) { |
| 732 return CFX_WideString(str1, str2); | 734 return CFX_WideString(str1, str2.AsWideStringC()); |
| 733 } | 735 } |
| 734 inline CFX_WideString operator+(const CFX_WideString& str1, | 736 inline CFX_WideString operator+(const CFX_WideString& str1, |
| 735 const CFX_WideStringC& str2) { | 737 const CFX_WideStringC& str2) { |
| 736 return CFX_WideString(str1, str2); | 738 return CFX_WideString(str1.AsWideStringC(), str2); |
| 737 } | 739 } |
| 738 inline CFX_WideString operator+(const CFX_WideStringC& str1, | 740 inline CFX_WideString operator+(const CFX_WideStringC& str1, |
| 739 const CFX_WideString& str2) { | 741 const CFX_WideString& str2) { |
| 740 return CFX_WideString(str1, str2); | 742 return CFX_WideString(str1, str2.AsWideStringC()); |
| 741 } | 743 } |
| 742 inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) { | 744 inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) { |
| 743 return rhs == lhs; | 745 return rhs == lhs; |
| 744 } | 746 } |
| 745 inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { | 747 inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { |
| 746 return rhs == lhs; | 748 return rhs == lhs; |
| 747 } | 749 } |
| 748 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { | 750 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { |
| 749 return rhs != lhs; | 751 return rhs != lhs; |
| 750 } | 752 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 761 } | 763 } |
| 762 | 764 |
| 763 FX_FLOAT FX_atof(const CFX_ByteStringC& str); | 765 FX_FLOAT FX_atof(const CFX_ByteStringC& str); |
| 764 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { | 766 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { |
| 765 return FX_atof(FX_UTF8Encode(wsStr.raw_str(), wsStr.GetLength()).c_str()); | 767 return FX_atof(FX_UTF8Encode(wsStr.raw_str(), wsStr.GetLength()).c_str()); |
| 766 } | 768 } |
| 767 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); | 769 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); |
| 768 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 770 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
| 769 | 771 |
| 770 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ | 772 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ |
| OLD | NEW |