OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 return *this; | 69 return *this; |
70 } | 70 } |
71 | 71 |
72 WEBKIT_EXPORT void reset(); | 72 WEBKIT_EXPORT void reset(); |
73 WEBKIT_EXPORT void assign(const WebString&); | 73 WEBKIT_EXPORT void assign(const WebString&); |
74 WEBKIT_EXPORT void assign(const WebUChar* data, size_t len); | 74 WEBKIT_EXPORT void assign(const WebUChar* data, size_t len); |
75 | 75 |
76 WEBKIT_EXPORT bool equals(const WebString& s) const; | 76 WEBKIT_EXPORT bool equals(const WebString& s) const; |
77 | 77 |
78 WEBKIT_EXPORT size_t length() const; | 78 WEBKIT_EXPORT size_t length() const; |
79 // Deprecated: This function will be removed once all its callers are gone. | |
79 WEBKIT_EXPORT const WebUChar* data() const; | 80 WEBKIT_EXPORT const WebUChar* data() const; |
80 | 81 |
81 bool isEmpty() const { return !length(); } | 82 bool isEmpty() const { return !length(); } |
82 bool isNull() const { return !m_private; } | 83 bool isNull() const { return !m_private; } |
83 | 84 |
84 WEBKIT_EXPORT WebCString utf8() const; | 85 WEBKIT_EXPORT WebCString utf8() const; |
85 | 86 |
86 WEBKIT_EXPORT static WebString fromUTF8(const char* data, size_t length); | 87 WEBKIT_EXPORT static WebString fromUTF8(const char* data, size_t length); |
87 WEBKIT_EXPORT static WebString fromUTF8(const char* data); | 88 WEBKIT_EXPORT static WebString fromUTF8(const char* data); |
88 | 89 |
(...skipping 25 matching lines...) Expand all Loading... | |
114 } | 115 } |
115 | 116 |
116 WebString& operator=(const string16& s) | 117 WebString& operator=(const string16& s) |
117 { | 118 { |
118 assign(s.data(), s.length()); | 119 assign(s.data(), s.length()); |
119 return *this; | 120 return *this; |
120 } | 121 } |
121 | 122 |
122 operator string16() const | 123 operator string16() const |
123 { | 124 { |
124 size_t len = length(); | 125 size_t len = length(); |
darin (slow to review)
2013/05/24 06:12:53
nit: this seems like a lot of code to inline into
| |
125 return len ? string16(data(), len) : string16(); | 126 if (!len) |
127 return string16(); | |
128 if (is8Bit()) { | |
129 const WebLChar* data = this->data8(); | |
130 return string16(data, data + len); | |
131 } | |
132 const WebUChar* data = this->data16(); | |
133 return string16(data, data + len); | |
126 } | 134 } |
127 | 135 |
128 WebString(const NullableString16& s) : m_private(0) | 136 WebString(const NullableString16& s) : m_private(0) |
129 { | 137 { |
130 if (s.is_null()) | 138 if (s.is_null()) |
131 reset(); | 139 reset(); |
132 else | 140 else |
133 assign(s.string().data(), s.string().length()); | 141 assign(s.string().data(), s.string().length()); |
134 } | 142 } |
135 | 143 |
136 WebString& operator=(const NullableString16& s) | 144 WebString& operator=(const NullableString16& s) |
137 { | 145 { |
138 if (s.is_null()) | 146 if (s.is_null()) |
139 reset(); | 147 reset(); |
140 else | 148 else |
141 assign(s.string().data(), s.string().length()); | 149 assign(s.string().data(), s.string().length()); |
142 return *this; | 150 return *this; |
143 } | 151 } |
144 | 152 |
145 operator NullableString16() const | 153 operator NullableString16() const |
146 { | 154 { |
147 if (!m_private) | 155 if (!m_private) |
148 return NullableString16(string16(), true); | 156 return NullableString16(string16(), true); |
149 size_t len = length(); | 157 return NullableString16(operator string16(), false); |
darin (slow to review)
2013/05/24 06:12:53
nit: You could reduce this code down to just:
r
abarth-chromium
2013/05/24 06:17:44
Good idea.
| |
150 return NullableString16(len ? string16(data(), len) : string16(), false) ; | |
151 } | 158 } |
152 | 159 |
153 template <class UTF8String> | 160 template <class UTF8String> |
154 static WebString fromUTF8(const UTF8String& s) | 161 static WebString fromUTF8(const UTF8String& s) |
155 { | 162 { |
156 return fromUTF8(s.data(), s.length()); | 163 return fromUTF8(s.data(), s.length()); |
157 } | 164 } |
158 #endif | 165 #endif |
159 | 166 |
160 private: | 167 private: |
168 WEBKIT_EXPORT bool is8Bit() const; | |
169 WEBKIT_EXPORT const WebLChar* data8() const; | |
170 WEBKIT_EXPORT const WebUChar* data16() const; | |
171 | |
161 void assign(WebStringPrivate*); | 172 void assign(WebStringPrivate*); |
162 WebStringPrivate* m_private; | 173 WebStringPrivate* m_private; |
163 }; | 174 }; |
164 | 175 |
165 inline bool operator==(const WebString& a, const WebString& b) | 176 inline bool operator==(const WebString& a, const WebString& b) |
166 { | 177 { |
167 return a.equals(b); | 178 return a.equals(b); |
168 } | 179 } |
169 | 180 |
170 inline bool operator!=(const WebString& a, const WebString& b) | 181 inline bool operator!=(const WebString& a, const WebString& b) |
171 { | 182 { |
172 return !(a == b); | 183 return !(a == b); |
173 } | 184 } |
174 | 185 |
175 } // namespace WebKit | 186 } // namespace WebKit |
176 | 187 |
177 #endif | 188 #endif |
OLD | NEW |