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

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

Issue 1127753002: Fix issues with != and == in fx_basic_wstring (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Missing & Created 5 years, 7 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
« no previous file with comments | « no previous file | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | core/src/fxcrt/fx_basic_wstring.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 _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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 504
505 CFX_WideStringC& operator = (const CFX_WideStringC& src) 505 CFX_WideStringC& operator = (const CFX_WideStringC& src)
506 { 506 {
507 m_Ptr = src.m_Ptr; 507 m_Ptr = src.m_Ptr;
508 m_Length = src.m_Length; 508 m_Length = src.m_Length;
509 return *this; 509 return *this;
510 } 510 }
511 511
512 CFX_WideStringC& operator = (const CFX_WideString& src); 512 CFX_WideStringC& operator = (const CFX_WideString& src);
513 513
514 bool» » » operator == (const CFX_WideStringC& str) const 514 bool operator== (const wchar_t* ptr) const {
515 { 515 return FXSYS_wcslen(ptr) == m_Length &&
516 return »str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L ength * sizeof(FX_WCHAR)) == 0; 516 wmemcmp(ptr, m_Ptr, m_Length) == 0;
517 } 517 }
518 518 bool operator== (const CFX_WideStringC& str) const {
519 bool» » » operator != (const CFX_WideStringC& str) const 519 return str.m_Length == m_Length &&
520 { 520 wmemcmp(str.m_Ptr, m_Ptr, m_Length) == 0;
521 return »str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L ength * sizeof(FX_WCHAR)) != 0; 521 }
522 bool operator!= (const wchar_t* ptr) const { return !(*this == ptr); }
523 bool operator!= (const CFX_WideStringC& str) const {
524 return !(*this == str);
522 } 525 }
523 526
524 FX_LPCWSTR GetPtr() const 527 FX_LPCWSTR GetPtr() const
525 { 528 {
526 return m_Ptr; 529 return m_Ptr;
527 } 530 }
528 531
529 FX_STRSIZE GetLength() const 532 FX_STRSIZE GetLength() const
530 { 533 {
531 return m_Length; 534 return m_Length;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 protected: 594 protected:
592 FX_LPCWSTR m_Ptr; 595 FX_LPCWSTR m_Ptr;
593 FX_STRSIZE m_Length; 596 FX_STRSIZE m_Length;
594 597
595 private: 598 private:
596 void* operator new (size_t) throw() 599 void* operator new (size_t) throw()
597 { 600 {
598 return NULL; 601 return NULL;
599 } 602 }
600 }; 603 };
604 inline bool operator== (const wchar_t* lhs, const CFX_WideStringC& rhs) {
605 return rhs == lhs;
606 }
607 inline bool operator!= (const wchar_t* lhs, const CFX_WideStringC& rhs) {
608 return rhs != lhs;
609 }
601 typedef const CFX_WideStringC& FX_WSTR; 610 typedef const CFX_WideStringC& FX_WSTR;
602 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) 611 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1)
612
603 struct CFX_StringDataW { 613 struct CFX_StringDataW {
604 intptr_t m_nRefs; // Would prefer ssize_t, but no windows support. 614 intptr_t m_nRefs; // Would prefer ssize_t, but no windows support.
605 FX_STRSIZE m_nDataLength; 615 FX_STRSIZE m_nDataLength;
606 FX_STRSIZE m_nAllocLength; 616 FX_STRSIZE m_nAllocLength;
607 FX_WCHAR m_String[1]; 617 FX_WCHAR m_String[1];
608 }; 618 };
609 619
610 // A mutable string with shared buffers using copy-on-write semantics that 620 // A mutable string with shared buffers using copy-on-write semantics that
611 // avoids the cost of std::string's iterator stability guarantees. 621 // avoids the cost of std::string's iterator stability guarantees.
612 class CFX_WideString 622 class CFX_WideString
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 const CFX_WideString& operator =(const CFX_WideStringC& stringSrc); 684 const CFX_WideString& operator =(const CFX_WideStringC& stringSrc);
675 685
676 const CFX_WideString& operator += (FX_LPCWSTR str); 686 const CFX_WideString& operator += (FX_LPCWSTR str);
677 687
678 const CFX_WideString& operator += (FX_WCHAR ch); 688 const CFX_WideString& operator += (FX_WCHAR ch);
679 689
680 const CFX_WideString& operator += (const CFX_WideString& str); 690 const CFX_WideString& operator += (const CFX_WideString& str);
681 691
682 const CFX_WideString& operator += (const CFX_WideStringC& str); 692 const CFX_WideString& operator += (const CFX_WideStringC& str);
683 693
694 bool operator== (const wchar_t* ptr) const { return Equal(ptr); }
695 bool operator== (const CFX_WideStringC& str) const { return Equal(str); }
696 bool operator== (const CFX_WideString& other) const { return Equal(other); }
697
698 bool operator!= (const wchar_t* ptr) const { return !(*this == ptr); }
699 bool operator!= (const CFX_WideStringC& str) const {
700 return !(*this == str);
701 }
702 bool operator!= (const CFX_WideString& other) const {
703 return !(*this == other);
704 }
705
684 bool operator< (const CFX_WideString& str) const { 706 bool operator< (const CFX_WideString& str) const {
685 int result = wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.Get Length())); 707 int result = wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.Get Length()));
686 return result < 0 || (result == 0 && GetLength() < str.GetLength()); 708 return result < 0 || (result == 0 && GetLength() < str.GetLength());
687 } 709 }
688 710
689 FX_WCHAR GetAt(FX_STRSIZE nIndex) const 711 FX_WCHAR GetAt(FX_STRSIZE nIndex) const
690 { 712 {
691 return m_pData ? m_pData->m_String[nIndex] : 0; 713 return m_pData ? m_pData->m_String[nIndex] : 0;
692 } 714 }
693 715
694 FX_WCHAR operator[](FX_STRSIZE nIndex) const 716 FX_WCHAR operator[](FX_STRSIZE nIndex) const
695 { 717 {
696 return m_pData ? m_pData->m_String[nIndex] : 0; 718 return m_pData ? m_pData->m_String[nIndex] : 0;
697 } 719 }
698 720
699 void SetAt(FX_STRSIZE nIndex, FX_WCHA R ch); 721 void SetAt(FX_STRSIZE nIndex, FX_WCHA R ch);
700 722
701 int Compare(FX_LPCWSTR str) const; 723 int Compare(FX_LPCWSTR str) const;
702 724
703 int Compare(const CFX_WideString& st r) const; 725 int Compare(const CFX_WideString& st r) const;
704 726
705 int CompareNoCase(FX_LPCWSTR str) co nst; 727 int CompareNoCase(FX_LPCWSTR str) co nst;
706 728
707 bool» » » » » Equal(const CFX_WideStringC& str ) const; 729 bool Equal(const wchar_t* ptr) const;
730 bool Equal(const CFX_WideStringC& str) const;
731 bool Equal(const CFX_WideString& other) const;
708 732
709 CFX_WideString Mid(FX_STRSIZE first) const; 733 CFX_WideString Mid(FX_STRSIZE first) const;
710 734
711 CFX_WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const; 735 CFX_WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const;
712 736
713 CFX_WideString Left(FX_STRSIZE count) const; 737 CFX_WideString Left(FX_STRSIZE count) const;
714 738
715 CFX_WideString Right(FX_STRSIZE count) const; 739 CFX_WideString Right(FX_STRSIZE count) const;
716 740
717 FX_STRSIZE Insert(FX_STRSIZE index, FX_WCHAR ch); 741 FX_STRSIZE Insert(FX_STRSIZE index, FX_WCHAR ch);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 return CFX_WideString(str1, str2); 849 return CFX_WideString(str1, str2);
826 } 850 }
827 inline CFX_WideString operator + (const CFX_WideString& str1, const CFX_WideStri ngC& str2) 851 inline CFX_WideString operator + (const CFX_WideString& str1, const CFX_WideStri ngC& str2)
828 { 852 {
829 return CFX_WideString(str1, str2); 853 return CFX_WideString(str1, str2);
830 } 854 }
831 inline CFX_WideString operator + (const CFX_WideStringC& str1, const CFX_WideStr ing& str2) 855 inline CFX_WideString operator + (const CFX_WideStringC& str1, const CFX_WideStr ing& str2)
832 { 856 {
833 return CFX_WideString(str1, str2); 857 return CFX_WideString(str1, str2);
834 } 858 }
835 859 inline bool operator== (const wchar_t* lhs, const CFX_WideString& rhs) {
836 bool operator==(const CFX_WideString& s1, const CFX_WideString& s2); 860 return rhs == lhs;
837 bool operator==(const CFX_WideString& s1, const CFX_WideStringC& s2); 861 }
838 bool operator==(const CFX_WideStringC& s1, const CFX_WideString& s2); 862 inline bool operator== (const CFX_WideStringC& lhs, const CFX_WideString& rhs) {
839 bool operator== (const CFX_WideString& s1, FX_LPCWSTR s2); 863 return rhs == lhs;
840 bool operator==(FX_LPCWSTR s1, const CFX_WideString& s2); 864 }
841 bool operator!=(const CFX_WideString& s1, const CFX_WideString& s2); 865 inline bool operator!= (const wchar_t* lhs, const CFX_WideString& rhs) {
842 bool operator!=(const CFX_WideString& s1, const CFX_WideStringC& s2); 866 return rhs != lhs;
843 bool operator!=(const CFX_WideStringC& s1, const CFX_WideString& s2); 867 }
844 bool operator!= (const CFX_WideString& s1, FX_LPCWSTR s2); 868 inline bool operator!= (const CFX_WideStringC& lhs, const CFX_WideString& rhs) {
845 bool operator!=(FX_LPCWSTR s1, const CFX_WideString& s2); 869 return rhs != lhs;
870 }
846 FX_FLOAT FX_atof(FX_BSTR str); 871 FX_FLOAT FX_atof(FX_BSTR str);
847 void FX_atonum(FX_BSTR str, FX_BOOL& bInteger, void* pData); 872 void FX_atonum(FX_BSTR str, FX_BOOL& bInteger, void* pData);
848 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf); 873 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf);
849 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); 874 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len);
850 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) 875 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr)
851 { 876 {
852 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); 877 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength());
853 } 878 }
854 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) 879 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr)
855 { 880 {
856 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); 881 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength());
857 } 882 }
858 #endif 883 #endif
OLDNEW
« no previous file with comments | « no previous file | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | core/src/fxcrt/fx_basic_wstring.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698