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 _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. |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "fx_memory.h" | 13 #include "fx_memory.h" |
14 | 14 |
15 class CFX_ByteStringC; | 15 class CFX_BinaryBuf; |
16 class CFX_ByteString; | 16 class CFX_ByteString; |
17 class CFX_WideStringC; | |
18 class CFX_WideString; | 17 class CFX_WideString; |
19 struct CFX_CharMap; | 18 struct CFX_CharMap; |
20 class CFX_BinaryBuf; | |
21 typedef int FX_STRSIZE; | 19 typedef int FX_STRSIZE; |
22 class CFX_ByteStringL; | |
23 class CFX_WideStringL; | |
24 | 20 |
25 // An immutable string with caller-provided storage which must outlive the | 21 // An immutable string with caller-provided storage which must outlive the |
26 // string itself. | 22 // string itself. |
27 class CFX_ByteStringC | 23 class CFX_ByteStringC |
28 { | 24 { |
29 public: | 25 public: |
30 typedef FX_CHAR value_type; | 26 typedef FX_CHAR value_type; |
31 | 27 |
32 CFX_ByteStringC() | 28 CFX_ByteStringC() |
33 { | 29 { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 197 |
202 CFX_ByteString() | 198 CFX_ByteString() |
203 { | 199 { |
204 m_pData = NULL; | 200 m_pData = NULL; |
205 } | 201 } |
206 | 202 |
207 CFX_ByteString(const CFX_ByteString& str); | 203 CFX_ByteString(const CFX_ByteString& str); |
208 | 204 |
209 CFX_ByteString(char ch); | 205 CFX_ByteString(char ch); |
210 | 206 |
211 CFX_ByteString(FX_LPCSTR ptr, FX_STRSIZE len = -1); | 207 CFX_ByteString(FX_LPCSTR ptr) |
Lei Zhang
2015/05/05 21:31:56
We should mark a whole bunch of these ctors explic
| |
208 : CFX_ByteString(ptr, ptr ? FXSYS_strlen(ptr) : 0) { } | |
209 | |
210 CFX_ByteString(FX_LPCSTR ptr, FX_STRSIZE len); | |
212 | 211 |
213 CFX_ByteString(FX_LPCBYTE ptr, FX_STRSIZE len); | 212 CFX_ByteString(FX_LPCBYTE ptr, FX_STRSIZE len); |
214 | 213 |
215 CFX_ByteString(FX_BSTR bstrc); | 214 CFX_ByteString(FX_BSTR bstrc); |
216 | |
217 CFX_ByteString(FX_BSTR bstrc1, FX_BSTR bstrc2); | 215 CFX_ByteString(FX_BSTR bstrc1, FX_BSTR bstrc2); |
218 | 216 |
219 ~CFX_ByteString(); | 217 ~CFX_ByteString(); |
220 | 218 |
221 static CFX_ByteString FromUnicode(FX_LPCWSTR ptr, FX_STRSIZE len = -1) ; | 219 static CFX_ByteString FromUnicode(FX_LPCWSTR ptr, FX_STRSIZE len = -1) ; |
222 | 220 |
223 static CFX_ByteString FromUnicode(const CFX_WideString& str); | 221 static CFX_ByteString FromUnicode(const CFX_WideString& str); |
224 | 222 |
225 // Explicit conversion to raw string | 223 // Explicit conversion to raw string |
226 FX_LPCSTR c_str() const | 224 FX_LPCSTR c_str() const |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 public: | 622 public: |
625 typedef FX_WCHAR value_type; | 623 typedef FX_WCHAR value_type; |
626 | 624 |
627 CFX_WideString() | 625 CFX_WideString() |
628 { | 626 { |
629 m_pData = NULL; | 627 m_pData = NULL; |
630 } | 628 } |
631 | 629 |
632 CFX_WideString(const CFX_WideString& str); | 630 CFX_WideString(const CFX_WideString& str); |
633 | 631 |
634 CFX_WideString(FX_LPCWSTR ptr, FX_STRSIZE len = -1) | 632 CFX_WideString(FX_LPCWSTR ptr) |
635 { | 633 : CFX_WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) { } |
636 InitStr(ptr, len); | 634 |
637 } | 635 CFX_WideString(FX_LPCWSTR ptr, FX_STRSIZE len); |
638 | 636 |
639 CFX_WideString(FX_WCHAR ch); | 637 CFX_WideString(FX_WCHAR ch); |
640 | 638 |
641 CFX_WideString(const CFX_WideStringC& str); | 639 CFX_WideString(const CFX_WideStringC& str); |
642 | 640 |
643 CFX_WideString(const CFX_WideStringC& str1, const CFX_WideStringC& str2); | 641 CFX_WideString(const CFX_WideStringC& str1, const CFX_WideStringC& str2); |
644 | 642 |
645 ~CFX_WideString(); | 643 ~CFX_WideString(); |
646 | 644 |
647 static CFX_WideString FromLocal(const char* str, FX_STRSIZE len = -1); | 645 static CFX_WideString FromLocal(const char* str, FX_STRSIZE len = -1); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
778 | 776 |
779 FX_STRSIZE Replace(FX_LPCWSTR lpszOld, FX_LPCWSTR l pszNew); | 777 FX_STRSIZE Replace(FX_LPCWSTR lpszOld, FX_LPCWSTR l pszNew); |
780 | 778 |
781 FX_STRSIZE Remove(FX_WCHAR ch); | 779 FX_STRSIZE Remove(FX_WCHAR ch); |
782 | 780 |
783 CFX_ByteString UTF8Encode() const; | 781 CFX_ByteString UTF8Encode() const; |
784 | 782 |
785 CFX_ByteString UTF16LE_Encode() const; | 783 CFX_ByteString UTF16LE_Encode() const; |
786 | 784 |
787 void ConvertFrom(const CFX_ByteString & str, CFX_CharMap* pCharMap = NULL); | 785 void ConvertFrom(const CFX_ByteString & str, CFX_CharMap* pCharMap = NULL); |
786 | |
788 protected: | 787 protected: |
789 void InitStr(FX_LPCWSTR ptr, int len) ; | |
790 | |
791 CFX_StringDataW* m_pData; | |
792 void CopyBeforeWrite(); | 788 void CopyBeforeWrite(); |
793 void AllocBeforeWrite(FX_STRSIZE nLen ); | 789 void AllocBeforeWrite(FX_STRSIZE nLen ); |
794 void ConcatInPlace(FX_STRSIZE nSrcLen , FX_LPCWSTR lpszSrcData); | 790 void ConcatInPlace(FX_STRSIZE nSrcLen , FX_LPCWSTR lpszSrcData); |
795 void ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCWSTR lpszSrc1Data, FX_STRSIZE nSrc2Len, FX_LPCWSTR lpszSrc2Data); | 791 void ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCWSTR lpszSrc1Data, FX_STRSIZE nSrc2Len, FX_LPCWSTR lpszSrc2Data); |
796 void AssignCopy(FX_STRSIZE nSrcLen, F X_LPCWSTR lpszSrcData); | 792 void AssignCopy(FX_STRSIZE nSrcLen, F X_LPCWSTR lpszSrcData); |
797 void AllocCopy(CFX_WideString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const; | 793 void AllocCopy(CFX_WideString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const; |
794 | |
795 CFX_StringDataW* m_pData; | |
798 }; | 796 }; |
799 inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src) | 797 inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src) |
800 { | 798 { |
801 m_Ptr = src.c_str(); | 799 m_Ptr = src.c_str(); |
802 m_Length = src.GetLength(); | 800 m_Length = src.GetLength(); |
803 } | 801 } |
804 inline CFX_WideStringC& CFX_WideStringC::operator = (const CFX_WideString& src) | 802 inline CFX_WideStringC& CFX_WideStringC::operator = (const CFX_WideString& src) |
805 { | 803 { |
806 m_Ptr = src.c_str(); | 804 m_Ptr = src.c_str(); |
807 m_Length = src.GetLength(); | 805 m_Length = src.GetLength(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); | 872 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); |
875 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) | 873 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) |
876 { | 874 { |
877 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 875 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); |
878 } | 876 } |
879 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) | 877 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) |
880 { | 878 { |
881 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 879 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
882 } | 880 } |
883 #endif | 881 #endif |
OLD | NEW |