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

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

Issue 808553013: Finish unit test for CFX_ByteStringC class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Soften up comment 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
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;
(...skipping 19 matching lines...) Expand all
30 m_Ptr = ptr; 30 m_Ptr = ptr;
31 m_Length = size; 31 m_Length = size;
32 } 32 }
33 33
34 CFX_ByteStringC(FX_LPCSTR ptr) 34 CFX_ByteStringC(FX_LPCSTR ptr)
35 { 35 {
36 m_Ptr = (FX_LPCBYTE)ptr; 36 m_Ptr = (FX_LPCBYTE)ptr;
37 m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0; 37 m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0;
38 } 38 }
39 39
40 // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However,
41 // the use of char rvalues are not caught at compile time. They are
42 // implicitly promoted to CFX_ByteString (see below) and then the
43 // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate
44 // constructor below. The CFX_ByteString then typically goes out of scope
45 // and |m_Ptr| may be left pointing to invalid memory. Beware.
46 // TODO(tsepez): Mark single-argument string constructors as explicit.
brucedawson 2015/01/06 18:27:21 Perhaps put a comment above the class declaration
Tom Sepez 2015/01/06 18:45:21 Done. Much better.
40 CFX_ByteStringC(FX_CHAR& ch) 47 CFX_ByteStringC(FX_CHAR& ch)
41 { 48 {
42 m_Ptr = (FX_LPCBYTE)&ch; 49 m_Ptr = (FX_LPCBYTE)&ch;
43 m_Length = 1; 50 m_Length = 1;
44 } 51 }
45 52
46 CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len) 53 CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len)
47 { 54 {
48 m_Ptr = (FX_LPCBYTE)ptr; 55 m_Ptr = (FX_LPCBYTE)ptr;
49 if (len == -1) { 56 if (len == -1) {
50 m_Length = (FX_STRSIZE)FXSYS_strlen(ptr); 57 m_Length = (FX_STRSIZE)FXSYS_strlen(ptr);
51 } else { 58 } else {
52 m_Length = len; 59 m_Length = len;
53 } 60 }
54 } 61 }
55 62
56 CFX_ByteStringC(const CFX_ByteStringC& src) 63 CFX_ByteStringC(const CFX_ByteStringC& src)
57 { 64 {
58 m_Ptr = src.m_Ptr; 65 m_Ptr = src.m_Ptr;
59 m_Length = src.m_Length; 66 m_Length = src.m_Length;
60 } 67 }
61 68
62 CFX_ByteStringC(const CFX_ByteString& src); 69 CFX_ByteStringC(const CFX_ByteString& src);
63 70
64 CFX_ByteStringC& operator = (FX_LPCSTR src) 71 CFX_ByteStringC& operator = (FX_LPCSTR src)
65 { 72 {
66 m_Ptr = (FX_LPCBYTE)src; 73 m_Ptr = (FX_LPCBYTE)src;
67 m_Length = (FX_STRSIZE)FXSYS_strlen(src); 74 m_Length = m_Ptr ? (FX_STRSIZE)FXSYS_strlen(src) : 0;
68 return *this; 75 return *this;
69 } 76 }
70 77
71 CFX_ByteStringC& operator = (const CFX_ByteStringC& src) 78 CFX_ByteStringC& operator = (const CFX_ByteStringC& src)
72 { 79 {
73 m_Ptr = src.m_Ptr; 80 m_Ptr = src.m_Ptr;
74 m_Length = src.m_Length; 81 m_Length = src.m_Length;
75 return *this; 82 return *this;
76 } 83 }
77 84
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); 858 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len);
852 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) 859 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr)
853 { 860 {
854 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); 861 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength());
855 } 862 }
856 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) 863 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr)
857 { 864 {
858 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); 865 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength());
859 } 866 }
860 #endif 867 #endif
OLDNEW
« no previous file with comments | « no previous file | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | core/src/fxcrt/fx_basic_bstring_unittest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698