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

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

Issue 1095893005: Merge to XFA: Add missing operators for CFX_xxxString combo patch. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 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
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp » ('j') | no next file with comments »
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 <algorithm>
11
10 #include "fx_memory.h" 12 #include "fx_memory.h"
11 13
12 class CFX_ByteStringC; 14 class CFX_ByteStringC;
13 class CFX_ByteString; 15 class CFX_ByteString;
14 class CFX_WideStringC; 16 class CFX_WideStringC;
15 class CFX_WideString; 17 class CFX_WideString;
16 struct CFX_CharMap; 18 struct CFX_CharMap;
17 class CFX_BinaryBuf; 19 class CFX_BinaryBuf;
18 typedef int FX_STRSIZE; 20 typedef int FX_STRSIZE;
19 class CFX_ByteStringL; 21 class CFX_ByteStringL;
20 class CFX_WideStringL; 22 class CFX_WideStringL;
21 23
22 // An immutable string with caller-provided storage which must outlive the 24 // An immutable string with caller-provided storage which must outlive the
23 // string itself. 25 // string itself.
24 class CFX_ByteStringC 26 class CFX_ByteStringC
25 { 27 {
26 public: 28 public:
27 typedef FX_CHAR value_type; 29 typedef FX_CHAR value_type;
28 30
29 CFX_ByteStringC() 31 CFX_ByteStringC()
30 { 32 {
31 m_Ptr = NULL; 33 m_Ptr = NULL;
32 m_Length = 0; 34 m_Length = 0;
33 } 35 }
34 36
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 95
94 bool operator == (const CFX_ByteStringC& str) const 96 bool operator == (const CFX_ByteStringC& str) const
95 { 97 {
96 return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L ength) == 0; 98 return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L ength) == 0;
97 } 99 }
98 100
99 bool operator != (const CFX_ByteStringC& str) const 101 bool operator != (const CFX_ByteStringC& str) const
100 { 102 {
101 return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L ength) != 0; 103 return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_L ength) != 0;
102 } 104 }
103 #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4))
104 105
105 FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; 106 FX_DWORD GetID(FX_STRSIZE start_pos = 0) const;
106 107
107 FX_LPCBYTE GetPtr() const 108 FX_LPCBYTE GetPtr() const
108 { 109 {
109 return m_Ptr; 110 return m_Ptr;
110 } 111 }
111 112
112 FX_LPCSTR GetCStr() const 113 FX_LPCSTR GetCStr() const
113 { 114 {
114 return (FX_LPCSTR)m_Ptr; 115 return (FX_LPCSTR)m_Ptr;
115 } 116 }
116 117
117 FX_STRSIZE GetLength() const 118 FX_STRSIZE GetLength() const
118 { 119 {
119 return m_Length; 120 return m_Length;
120 } 121 }
121 122
122 bool IsEmpty() const 123 bool IsEmpty() const
123 { 124 {
124 return m_Length == 0; 125 return m_Length == 0;
125 } 126 }
126 127
127 operator FX_LPCBYTE() const
128 {
129 return m_Ptr;
130 }
131
132 FX_BYTE GetAt(FX_STRSIZE index) const 128 FX_BYTE GetAt(FX_STRSIZE index) const
133 { 129 {
134 return m_Ptr[index]; 130 return m_Ptr[index];
135 } 131 }
136 132
137 CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const 133 CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const
138 { 134 {
139 if (index < 0) { 135 if (index < 0) {
140 index = 0; 136 index = 0;
141 } 137 }
142 if (index > m_Length) { 138 if (index > m_Length) {
143 return CFX_ByteStringC(); 139 return CFX_ByteStringC();
144 } 140 }
145 if (count < 0 || count > m_Length - index) { 141 if (count < 0 || count > m_Length - index) {
146 count = m_Length - index; 142 count = m_Length - index;
147 } 143 }
148 return CFX_ByteStringC(m_Ptr + index, count); 144 return CFX_ByteStringC(m_Ptr + index, count);
149 } 145 }
146
147 const FX_BYTE& operator[] (size_t index) const
148 {
149 return m_Ptr[index];
150 }
151
152 bool operator< (const CFX_ByteStringC& that) const
153 {
154 int result = memcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length) );
155 return result < 0 || (result == 0 && m_Length < that.m_Length);
156 }
157
150 protected: 158 protected:
159 FX_LPCBYTE m_Ptr;
160 FX_STRSIZE m_Length;
151 161
152 FX_LPCBYTE m_Ptr;
153
154 FX_STRSIZE m_Length;
155 private: 162 private:
156
157 void* operator new (size_t) throw() 163 void* operator new (size_t) throw()
158 { 164 {
159 return NULL; 165 return NULL;
160 } 166 }
161 }; 167 };
162 typedef const CFX_ByteStringC& FX_BSTR; 168 typedef const CFX_ByteStringC& FX_BSTR;
163 #define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1) 169 #define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1)
170 #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4))
164 struct CFX_StringData { 171 struct CFX_StringData {
165 172
166 long m_nRefs; 173 long m_nRefs;
167 174
168 FX_STRSIZE m_nDataLength; 175 FX_STRSIZE m_nDataLength;
169 176
170 FX_STRSIZE m_nAllocLength; 177 FX_STRSIZE m_nAllocLength;
171 178
172 FX_CHAR m_String[1]; 179 FX_CHAR m_String[1];
173 }; 180 };
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 bool operator != (FX_BSTR str) const 261 bool operator != (FX_BSTR str) const
255 { 262 {
256 return !Equal(str); 263 return !Equal(str);
257 } 264 }
258 265
259 bool operator != (const CFX_ByteStrin g& str) const 266 bool operator != (const CFX_ByteStrin g& str) const
260 { 267 {
261 return !operator==(str); 268 return !operator==(str);
262 } 269 }
263 270
271 bool operator< (const CFX_ByteString& str) const
272 {
273 int result = FXSYS_memcmp32(c_str(), str.c_str(), std::min(GetLength(), str.GetLength()));
274 return result < 0 || (result == 0 && GetLength() < str.GetLength());
275 }
276
264 void Empty(); 277 void Empty();
265 278
266 const CFX_ByteString& operator = (FX_LPCSTR str); 279 const CFX_ByteString& operator = (FX_LPCSTR str);
267 280
268 const CFX_ByteString& operator = (FX_BSTR bstrc); 281 const CFX_ByteString& operator = (FX_BSTR bstrc);
269 282
270 const CFX_ByteString& operator = (const CFX_ByteString& stringSrc); 283 const CFX_ByteString& operator = (const CFX_ByteString& stringSrc);
271 284
272 const CFX_ByteString& operator = (const CFX_BinaryBuf& buf); 285 const CFX_ByteString& operator = (const CFX_BinaryBuf& buf);
273 286
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 return CFX_ByteString(str1, str2); 434 return CFX_ByteString(str1, str2);
422 } 435 }
423 inline CFX_ByteString operator + (const CFX_ByteString& str1, FX_BSTR str2) 436 inline CFX_ByteString operator + (const CFX_ByteString& str1, FX_BSTR str2)
424 { 437 {
425 return CFX_ByteString(str1, str2); 438 return CFX_ByteString(str1, str2);
426 } 439 }
427 inline CFX_ByteString operator + (FX_BSTR str1, const CFX_ByteString& str2) 440 inline CFX_ByteString operator + (FX_BSTR str1, const CFX_ByteString& str2)
428 { 441 {
429 return CFX_ByteString(str1, str2); 442 return CFX_ByteString(str1, str2);
430 } 443 }
431 class CFX_WideStringC 444 class CFX_WideStringC
432 { 445 {
433 public: 446 public:
434 typedef FX_WCHAR value_type; 447 typedef FX_WCHAR value_type;
435 448
436 CFX_WideStringC() 449 CFX_WideStringC()
437 { 450 {
438 m_Ptr = NULL; 451 m_Ptr = NULL;
439 m_Length = 0; 452 m_Length = 0;
440 } 453 }
441 454
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 CFX_WideStringC Right(FX_STRSIZE count) const 556 CFX_WideStringC Right(FX_STRSIZE count) const
544 { 557 {
545 if (count < 1) { 558 if (count < 1) {
546 return CFX_WideStringC(); 559 return CFX_WideStringC();
547 } 560 }
548 if (count > m_Length) { 561 if (count > m_Length) {
549 count = m_Length; 562 count = m_Length;
550 } 563 }
551 return CFX_WideStringC(m_Ptr + m_Length - count, count); 564 return CFX_WideStringC(m_Ptr + m_Length - count, count);
552 } 565 }
566
567 const FX_WCHAR& operator[] (size_t index) const
568 {
569 return m_Ptr[index];
570 }
571
572 bool operator< (const CFX_WideStringC& that) const
573 {
574 int result = wmemcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length ));
575 return result < 0 || (result == 0 && m_Length < that.m_Length);
576 }
577
553 protected: 578 protected:
579 FX_LPCWSTR m_Ptr;
580 FX_STRSIZE m_Length;
554 581
555 FX_LPCWSTR m_Ptr;
556
557 FX_STRSIZE m_Length;
558 private: 582 private:
559
560 void* operator new (size_t) throw() 583 void* operator new (size_t) throw()
561 { 584 {
562 return NULL; 585 return NULL;
563 } 586 }
564 }; 587 };
565 typedef const CFX_WideStringC& FX_WSTR; 588 typedef const CFX_WideStringC& FX_WSTR;
566 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) 589 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1)
567 struct CFX_StringDataW { 590 struct CFX_StringDataW {
568 591
569 long m_nRefs; 592 long m_nRefs;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 const CFX_WideString& operator =(const CFX_WideStringC& stringSrc); 662 const CFX_WideString& operator =(const CFX_WideStringC& stringSrc);
640 663
641 const CFX_WideString& operator += (FX_LPCWSTR str); 664 const CFX_WideString& operator += (FX_LPCWSTR str);
642 665
643 const CFX_WideString& operator += (FX_WCHAR ch); 666 const CFX_WideString& operator += (FX_WCHAR ch);
644 667
645 const CFX_WideString& operator += (const CFX_WideString& str); 668 const CFX_WideString& operator += (const CFX_WideString& str);
646 669
647 const CFX_WideString& operator += (const CFX_WideStringC& str); 670 const CFX_WideString& operator += (const CFX_WideStringC& str);
648 671
672 bool operator< (const CFX_WideString& str) const {
673 int result = wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.Get Length()));
674 return result < 0 || (result == 0 && GetLength() < str.GetLength());
675 }
676
649 FX_WCHAR GetAt(FX_STRSIZE nIndex) const 677 FX_WCHAR GetAt(FX_STRSIZE nIndex) const
650 { 678 {
651 return m_pData ? m_pData->m_String[nIndex] : 0; 679 return m_pData ? m_pData->m_String[nIndex] : 0;
652 } 680 }
653 681
654 FX_WCHAR operator[](FX_STRSIZE nIndex) const 682 FX_WCHAR operator[](FX_STRSIZE nIndex) const
655 { 683 {
656 return m_pData ? m_pData->m_String[nIndex] : 0; 684 return m_pData ? m_pData->m_String[nIndex] : 0;
657 } 685 }
658 686
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); 839 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len);
812 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) 840 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr)
813 { 841 {
814 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); 842 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength());
815 } 843 }
816 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) 844 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr)
817 { 845 {
818 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); 846 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength());
819 } 847 }
820 #endif 848 #endif
OLDNEW
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698