Changeset 56864 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Mar 31, 2010, 1:36:21 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.cpp
r56560 r56864 58 58 extern const double Inf; 59 59 60 CString::CString(const char* c)61 : m_length(strlen(c))62 , m_data(new char[m_length + 1])63 {64 memcpy(m_data, c, m_length + 1);65 }66 67 CString::CString(const char* c, size_t length)68 : m_length(length)69 , m_data(new char[length + 1])70 {71 memcpy(m_data, c, m_length);72 m_data[m_length] = 0;73 }74 75 CString::CString(const CString& b)76 {77 m_length = b.m_length;78 if (b.m_data) {79 m_data = new char[m_length + 1];80 memcpy(m_data, b.m_data, m_length + 1);81 } else82 m_data = 0;83 }84 85 CString::~CString()86 {87 delete [] m_data;88 }89 90 CString CString::adopt(char* c, size_t length)91 {92 CString s;93 s.m_data = c;94 s.m_length = length;95 return s;96 }97 98 CString& CString::append(const CString& t)99 {100 char* n;101 n = new char[m_length + t.m_length + 1];102 if (m_length)103 memcpy(n, m_data, m_length);104 if (t.m_length)105 memcpy(n + m_length, t.m_data, t.m_length);106 m_length += t.m_length;107 n[m_length] = 0;108 109 delete [] m_data;110 m_data = n;111 112 return *this;113 }114 115 CString& CString::operator=(const char* c)116 {117 if (m_data)118 delete [] m_data;119 m_length = strlen(c);120 m_data = new char[m_length + 1];121 memcpy(m_data, c, m_length + 1);122 123 return *this;124 }125 126 CString& CString::operator=(const CString& str)127 {128 if (this == &str)129 return *this;130 131 if (m_data)132 delete [] m_data;133 m_length = str.m_length;134 if (str.m_data) {135 m_data = new char[m_length + 1];136 memcpy(m_data, str.m_data, m_length + 1);137 } else138 m_data = 0;139 140 return *this;141 }142 143 bool operator==(const CString& c1, const CString& c2)144 {145 size_t len = c1.length();146 return len == c2.length() && (len == 0 || memcmp(c1.data(), c2.data(), len) == 0);147 }148 149 60 // The null string is immutable, except for refCount. 150 61 UString::Rep* UString::s_nullRep; -
trunk/JavaScriptCore/runtime/UString.h
r56560 r56864 34 34 #include <wtf/RefPtr.h> 35 35 #include <wtf/Vector.h> 36 #include <wtf/text/CString.h> 36 37 #include <wtf/unicode/Unicode.h> 37 38 … … 40 41 using WTF::PlacementNewAdoptType; 41 42 using WTF::PlacementNewAdopt; 42 43 class CString {44 public:45 CString()46 : m_length(0)47 , m_data(0)48 {49 }50 51 CString(const char*);52 CString(const char*, size_t);53 CString(const CString&);54 55 ~CString();56 57 static CString adopt(char*, size_t); // buffer should be allocated with new[].58 59 CString& append(const CString&);60 CString& operator=(const char* c);61 CString& operator=(const CString&);62 CString& operator+=(const CString& c) { return append(c); }63 64 size_t length() const { return m_length; }65 const char* data() const { return m_data; }66 67 private:68 size_t m_length;69 char* m_data;70 };71 72 bool operator==(const CString&, const CString&);73 74 typedef Vector<char, 32> CStringBuffer;75 43 76 44 class UString {
Note:
See TracChangeset
for help on using the changeset viewer.