| 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 class CFX_ByteStringC; | 9 class CFX_ByteStringC; |
| 10 class CFX_ByteString; | 10 class CFX_ByteString; |
| 11 class CFX_WideStringC; | 11 class CFX_WideStringC; |
| 12 class CFX_WideString; | 12 class CFX_WideString; |
| 13 struct CFX_CharMap; | 13 struct CFX_CharMap; |
| 14 class CFX_BinaryBuf; | 14 class CFX_BinaryBuf; |
| 15 typedef int FX_STRSIZE; | 15 typedef int FX_STRSIZE; |
| 16 class CFX_ByteStringL; | 16 class CFX_ByteStringL; |
| 17 class CFX_WideStringL; | 17 class CFX_WideStringL; |
| 18 |
| 19 // An immutable string with caller-provided storage which must outlive the |
| 20 // string itself. |
| 18 class CFX_ByteStringC : public CFX_Object | 21 class CFX_ByteStringC : public CFX_Object |
| 19 { | 22 { |
| 20 public: | 23 public: |
| 21 | 24 |
| 22 CFX_ByteStringC() | 25 CFX_ByteStringC() |
| 23 { | 26 { |
| 24 m_Ptr = NULL; | 27 m_Ptr = NULL; |
| 25 m_Length = 0; | 28 m_Length = 0; |
| 26 } | 29 } |
| 27 | 30 |
| 28 CFX_ByteStringC(FX_LPCBYTE ptr, FX_STRSIZE size) | 31 CFX_ByteStringC(FX_LPCBYTE ptr, FX_STRSIZE size) |
| 29 { | 32 { |
| 30 m_Ptr = ptr; | 33 m_Ptr = ptr; |
| 31 m_Length = size; | 34 m_Length = size; |
| 32 } | 35 } |
| 33 | 36 |
| 34 CFX_ByteStringC(FX_LPCSTR ptr) | 37 CFX_ByteStringC(FX_LPCSTR ptr) |
| 35 { | 38 { |
| 36 m_Ptr = (FX_LPCBYTE)ptr; | 39 m_Ptr = (FX_LPCBYTE)ptr; |
| 37 m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0; | 40 m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0; |
| 38 } | 41 } |
| 39 | 42 |
| 43 // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However, |
| 44 // the use of char rvalues are not caught at compile time. They are |
| 45 // implicitly promoted to CFX_ByteString (see below) and then the |
| 46 // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate |
| 47 // constructor below. The CFX_ByteString then typically goes out of scope |
| 48 // and |m_Ptr| may be left pointing to invalid memory. Beware. |
| 49 // TODO(tsepez): Mark single-argument string constructors as explicit. |
| 40 CFX_ByteStringC(FX_CHAR& ch) | 50 CFX_ByteStringC(FX_CHAR& ch) |
| 41 { | 51 { |
| 42 m_Ptr = (FX_LPCBYTE)&ch; | 52 m_Ptr = (FX_LPCBYTE)&ch; |
| 43 m_Length = 1; | 53 m_Length = 1; |
| 44 } | 54 } |
| 45 | 55 |
| 46 CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len) | 56 CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len) |
| 47 { | 57 { |
| 48 m_Ptr = (FX_LPCBYTE)ptr; | 58 m_Ptr = (FX_LPCBYTE)ptr; |
| 49 if (len == -1) { | 59 if (len == -1) { |
| 50 m_Length = (FX_STRSIZE)FXSYS_strlen(ptr); | 60 m_Length = (FX_STRSIZE)FXSYS_strlen(ptr); |
| 51 } else { | 61 } else { |
| 52 m_Length = len; | 62 m_Length = len; |
| 53 } | 63 } |
| 54 } | 64 } |
| 55 | 65 |
| 56 CFX_ByteStringC(const CFX_ByteStringC& src) | 66 CFX_ByteStringC(const CFX_ByteStringC& src) |
| 57 { | 67 { |
| 58 m_Ptr = src.m_Ptr; | 68 m_Ptr = src.m_Ptr; |
| 59 m_Length = src.m_Length; | 69 m_Length = src.m_Length; |
| 60 } | 70 } |
| 61 | 71 |
| 62 CFX_ByteStringC(const CFX_ByteString& src); | 72 CFX_ByteStringC(const CFX_ByteString& src); |
| 63 | 73 |
| 64 CFX_ByteStringC& operator = (FX_LPCSTR src) | 74 CFX_ByteStringC& operator = (FX_LPCSTR src) |
| 65 { | 75 { |
| 66 m_Ptr = (FX_LPCBYTE)src; | 76 m_Ptr = (FX_LPCBYTE)src; |
| 67 m_Length = (FX_STRSIZE)FXSYS_strlen(src); | 77 m_Length = m_Ptr ? (FX_STRSIZE)FXSYS_strlen(src) : 0; |
| 68 return *this; | 78 return *this; |
| 69 } | 79 } |
| 70 | 80 |
| 71 CFX_ByteStringC& operator = (const CFX_ByteStringC& src) | 81 CFX_ByteStringC& operator = (const CFX_ByteStringC& src) |
| 72 { | 82 { |
| 73 m_Ptr = src.m_Ptr; | 83 m_Ptr = src.m_Ptr; |
| 74 m_Length = src.m_Length; | 84 m_Length = src.m_Length; |
| 75 return *this; | 85 return *this; |
| 76 } | 86 } |
| 77 | 87 |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); | 861 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); |
| 852 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) | 862 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) |
| 853 { | 863 { |
| 854 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 864 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); |
| 855 } | 865 } |
| 856 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) | 866 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) |
| 857 { | 867 { |
| 858 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 868 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
| 859 } | 869 } |
| 860 #endif | 870 #endif |
| OLD | NEW |