Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: core/fxcrt/include/fx_string.h

Issue 1857073002: Make down-conversion explicit from CFX_Widetring to CFX_WideStringC. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Comment. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) { 422 CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) {
423 m_Ptr = ptr; 423 m_Ptr = ptr;
424 m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len; 424 m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len;
425 } 425 }
426 426
427 CFX_WideStringC(const CFX_WideStringC& src) { 427 CFX_WideStringC(const CFX_WideStringC& src) {
428 m_Ptr = src.m_Ptr; 428 m_Ptr = src.m_Ptr;
429 m_Length = src.m_Length; 429 m_Length = src.m_Length;
430 } 430 }
431 431
432 CFX_WideStringC(const CFX_WideString& src);
433
434 CFX_WideStringC& operator=(const FX_WCHAR* src) { 432 CFX_WideStringC& operator=(const FX_WCHAR* src) {
435 m_Ptr = src; 433 m_Ptr = src;
436 m_Length = FXSYS_wcslen(src); 434 m_Length = FXSYS_wcslen(src);
437 return *this; 435 return *this;
438 } 436 }
439 437
440 CFX_WideStringC& operator=(const CFX_WideStringC& src) { 438 CFX_WideStringC& operator=(const CFX_WideStringC& src) {
441 m_Ptr = src.m_Ptr; 439 m_Ptr = src.m_Ptr;
442 m_Length = src.m_Length; 440 m_Length = src.m_Length;
443 return *this; 441 return *this;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 static CFX_WideString FromLocal(const CFX_ByteString& str); 546 static CFX_WideString FromLocal(const CFX_ByteString& str);
549 static CFX_WideString FromCodePage(const CFX_ByteString& str, 547 static CFX_WideString FromCodePage(const CFX_ByteString& str,
550 uint16_t codepage); 548 uint16_t codepage);
551 549
552 static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len); 550 static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len);
553 static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); 551 static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len);
554 552
555 static FX_STRSIZE WStringLength(const unsigned short* str); 553 static FX_STRSIZE WStringLength(const unsigned short* str);
556 554
557 // Explicit conversion to C-style wide string. 555 // Explicit conversion to C-style wide string.
556 // Note: |this| must outlive the use of the result.
558 const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; } 557 const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; }
559 558
560 // Implicit conversion to C-style wide string -- deprecated. 559 // Implicit conversion to C-style wide string -- deprecated.
560 // Note: |this| must outlive the use of the result.
561 operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; } 561 operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; }
562 562
563 // Explicit conversion to CFX_WideStringC.
564 // Note: |this| must outlive the use of the result.
565 CFX_WideStringC AsWideStringC() const {
566 return CFX_WideStringC(c_str(), GetLength());
567 }
568
563 void Empty(); 569 void Empty();
564
565 bool IsEmpty() const { return !GetLength(); } 570 bool IsEmpty() const { return !GetLength(); }
566 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } 571 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
567 572
568 const CFX_WideString& operator=(const FX_WCHAR* str); 573 const CFX_WideString& operator=(const FX_WCHAR* str);
569 const CFX_WideString& operator=(const CFX_WideString& stringSrc); 574 const CFX_WideString& operator=(const CFX_WideString& stringSrc);
570 const CFX_WideString& operator=(const CFX_WideStringC& stringSrc); 575 const CFX_WideString& operator=(const CFX_WideStringC& stringSrc);
571 576
572 const CFX_WideString& operator+=(const FX_WCHAR* str); 577 const CFX_WideString& operator+=(const FX_WCHAR* str);
573 const CFX_WideString& operator+=(FX_WCHAR ch); 578 const CFX_WideString& operator+=(FX_WCHAR ch);
574 const CFX_WideString& operator+=(const CFX_WideString& str); 579 const CFX_WideString& operator+=(const CFX_WideString& str);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 FX_STRSIZE nSrc2Len, 681 FX_STRSIZE nSrc2Len,
677 const FX_WCHAR* lpszSrc2Data); 682 const FX_WCHAR* lpszSrc2Data);
678 void AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData); 683 void AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData);
679 void AllocCopy(CFX_WideString& dest, 684 void AllocCopy(CFX_WideString& dest,
680 FX_STRSIZE nCopyLen, 685 FX_STRSIZE nCopyLen,
681 FX_STRSIZE nCopyIndex) const; 686 FX_STRSIZE nCopyIndex) const;
682 687
683 StringData* m_pData; 688 StringData* m_pData;
684 friend class fxcrt_WideStringConcatInPlace_Test; 689 friend class fxcrt_WideStringConcatInPlace_Test;
685 }; 690 };
686 inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src) { 691
687 m_Ptr = src.c_str();
688 m_Length = src.GetLength();
689 }
690 inline CFX_WideStringC& CFX_WideStringC::operator=(const CFX_WideString& src) { 692 inline CFX_WideStringC& CFX_WideStringC::operator=(const CFX_WideString& src) {
691 m_Ptr = src.c_str(); 693 m_Ptr = src.c_str();
692 m_Length = src.GetLength(); 694 m_Length = src.GetLength();
693 return *this; 695 return *this;
694 } 696 }
695 697
696 inline CFX_WideString operator+(const CFX_WideStringC& str1, 698 inline CFX_WideString operator+(const CFX_WideStringC& str1,
697 const CFX_WideStringC& str2) { 699 const CFX_WideStringC& str2) {
698 return CFX_WideString(str1, str2); 700 return CFX_WideString(str1, str2);
699 } 701 }
700 inline CFX_WideString operator+(const CFX_WideStringC& str1, 702 inline CFX_WideString operator+(const CFX_WideStringC& str1,
701 const FX_WCHAR* str2) { 703 const FX_WCHAR* str2) {
702 return CFX_WideString(str1, str2); 704 return CFX_WideString(str1, str2);
703 } 705 }
704 inline CFX_WideString operator+(const FX_WCHAR* str1, 706 inline CFX_WideString operator+(const FX_WCHAR* str1,
705 const CFX_WideStringC& str2) { 707 const CFX_WideStringC& str2) {
706 return CFX_WideString(str1, str2); 708 return CFX_WideString(str1, str2);
707 } 709 }
708 inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) { 710 inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) {
709 return CFX_WideString(str1, CFX_WideStringC(ch)); 711 return CFX_WideString(str1, CFX_WideStringC(ch));
710 } 712 }
711 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideStringC& str2) { 713 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideStringC& str2) {
712 return CFX_WideString(ch, str2); 714 return CFX_WideString(ch, str2);
713 } 715 }
714 inline CFX_WideString operator+(const CFX_WideString& str1, 716 inline CFX_WideString operator+(const CFX_WideString& str1,
715 const CFX_WideString& str2) { 717 const CFX_WideString& str2) {
716 return CFX_WideString(str1, str2); 718 return CFX_WideString(str1.AsWideStringC(), str2.AsWideStringC());
717 } 719 }
718 inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) { 720 inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) {
719 return CFX_WideString(str1, CFX_WideStringC(ch)); 721 return CFX_WideString(str1.AsWideStringC(), CFX_WideStringC(ch));
720 } 722 }
721 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) { 723 inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) {
722 return CFX_WideString(ch, str2); 724 return CFX_WideString(ch, str2.AsWideStringC());
723 } 725 }
724 inline CFX_WideString operator+(const CFX_WideString& str1, 726 inline CFX_WideString operator+(const CFX_WideString& str1,
725 const FX_WCHAR* str2) { 727 const FX_WCHAR* str2) {
726 return CFX_WideString(str1, str2); 728 return CFX_WideString(str1.AsWideStringC(), str2);
727 } 729 }
728 inline CFX_WideString operator+(const FX_WCHAR* str1, 730 inline CFX_WideString operator+(const FX_WCHAR* str1,
729 const CFX_WideString& str2) { 731 const CFX_WideString& str2) {
730 return CFX_WideString(str1, str2); 732 return CFX_WideString(str1, str2.AsWideStringC());
731 } 733 }
732 inline CFX_WideString operator+(const CFX_WideString& str1, 734 inline CFX_WideString operator+(const CFX_WideString& str1,
733 const CFX_WideStringC& str2) { 735 const CFX_WideStringC& str2) {
734 return CFX_WideString(str1, str2); 736 return CFX_WideString(str1.AsWideStringC(), str2);
735 } 737 }
736 inline CFX_WideString operator+(const CFX_WideStringC& str1, 738 inline CFX_WideString operator+(const CFX_WideStringC& str1,
737 const CFX_WideString& str2) { 739 const CFX_WideString& str2) {
738 return CFX_WideString(str1, str2); 740 return CFX_WideString(str1, str2.AsWideStringC());
739 } 741 }
740 inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) { 742 inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) {
741 return rhs == lhs; 743 return rhs == lhs;
742 } 744 }
743 inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { 745 inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) {
744 return rhs == lhs; 746 return rhs == lhs;
745 } 747 }
746 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { 748 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) {
747 return rhs != lhs; 749 return rhs != lhs;
748 } 750 }
(...skipping 10 matching lines...) Expand all
759 } 761 }
760 762
761 FX_FLOAT FX_atof(const CFX_ByteStringC& str); 763 FX_FLOAT FX_atof(const CFX_ByteStringC& str);
762 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { 764 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) {
763 return FX_atof(FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()).c_str()); 765 return FX_atof(FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()).c_str());
764 } 766 }
765 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); 767 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData);
766 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); 768 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf);
767 769
768 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ 770 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698