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

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

Issue 837253002: Merge to XFA: Finish unit test for CFX_ByteStringC class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 11 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_bstring.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 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 typedef FX_CHAR value_type; 24 typedef FX_CHAR value_type;
22 25
23 CFX_ByteStringC() 26 CFX_ByteStringC()
24 { 27 {
25 m_Ptr = NULL; 28 m_Ptr = NULL;
26 m_Length = 0; 29 m_Length = 0;
27 } 30 }
28 31
29 CFX_ByteStringC(FX_LPCBYTE ptr, FX_STRSIZE size) 32 CFX_ByteStringC(FX_LPCBYTE ptr, FX_STRSIZE size)
30 { 33 {
31 m_Ptr = ptr; 34 m_Ptr = ptr;
32 m_Length = size; 35 m_Length = size;
33 } 36 }
34 37
35 CFX_ByteStringC(FX_LPCSTR ptr) 38 CFX_ByteStringC(FX_LPCSTR ptr)
36 { 39 {
37 m_Ptr = (FX_LPCBYTE)ptr; 40 m_Ptr = (FX_LPCBYTE)ptr;
38 m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0; 41 m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0;
39 } 42 }
40 43
44 // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However,
45 // the use of char rvalues are not caught at compile time. They are
46 // implicitly promoted to CFX_ByteString (see below) and then the
47 // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate
48 // constructor below. The CFX_ByteString then typically goes out of scope
49 // and |m_Ptr| may be left pointing to invalid memory. Beware.
50 // TODO(tsepez): Mark single-argument string constructors as explicit.
41 CFX_ByteStringC(FX_CHAR& ch) 51 CFX_ByteStringC(FX_CHAR& ch)
42 { 52 {
43 m_Ptr = (FX_LPCBYTE)&ch; 53 m_Ptr = (FX_LPCBYTE)&ch;
44 m_Length = 1; 54 m_Length = 1;
45 } 55 }
46 56
47 CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len) 57 CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len)
48 { 58 {
49 m_Ptr = (FX_LPCBYTE)ptr; 59 m_Ptr = (FX_LPCBYTE)ptr;
50 if (len == -1) { 60 if (len == -1) {
51 m_Length = (FX_STRSIZE)FXSYS_strlen(ptr); 61 m_Length = (FX_STRSIZE)FXSYS_strlen(ptr);
52 } else { 62 } else {
53 m_Length = len; 63 m_Length = len;
54 } 64 }
55 } 65 }
56 66
57 CFX_ByteStringC(const CFX_ByteStringC& src) 67 CFX_ByteStringC(const CFX_ByteStringC& src)
58 { 68 {
59 m_Ptr = src.m_Ptr; 69 m_Ptr = src.m_Ptr;
60 m_Length = src.m_Length; 70 m_Length = src.m_Length;
61 } 71 }
62 72
63 CFX_ByteStringC(const CFX_ByteString& src); 73 CFX_ByteStringC(const CFX_ByteString& src);
64 74
65 CFX_ByteStringC& operator = (FX_LPCSTR src) 75 CFX_ByteStringC& operator = (FX_LPCSTR src)
66 { 76 {
67 m_Ptr = (FX_LPCBYTE)src; 77 m_Ptr = (FX_LPCBYTE)src;
68 m_Length = (FX_STRSIZE)FXSYS_strlen(src); 78 m_Length = m_Ptr ? (FX_STRSIZE)FXSYS_strlen(src) : 0;
69 return *this; 79 return *this;
70 } 80 }
71 81
72 CFX_ByteStringC& operator = (const CFX_ByteStringC& src) 82 CFX_ByteStringC& operator = (const CFX_ByteStringC& src)
73 { 83 {
74 m_Ptr = src.m_Ptr; 84 m_Ptr = src.m_Ptr;
75 m_Length = src.m_Length; 85 m_Length = src.m_Length;
76 return *this; 86 return *this;
77 } 87 }
78 88
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); 865 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len);
856 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) 866 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr)
857 { 867 {
858 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); 868 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength());
859 } 869 }
860 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) 870 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr)
861 { 871 {
862 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); 872 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength());
863 } 873 }
864 #endif 874 #endif
OLDNEW
« no previous file with comments | « no previous file | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698