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 20 matching lines...) Expand all Loading... |
31 #ifndef WebString_h | 31 #ifndef WebString_h |
32 #define WebString_h | 32 #define WebString_h |
33 | 33 |
34 #include "WebCommon.h" | 34 #include "WebCommon.h" |
35 | 35 |
36 #if WEBKIT_IMPLEMENTATION | 36 #if WEBKIT_IMPLEMENTATION |
37 #include <wtf/Forward.h> | 37 #include <wtf/Forward.h> |
38 #else | 38 #else |
39 #include <base/nullable_string16.h> | 39 #include <base/nullable_string16.h> |
40 #include <base/string16.h> | 40 #include <base/string16.h> |
| 41 #include <base/strings/latin1_string_conversions.h> |
41 #endif | 42 #endif |
42 | 43 |
43 namespace WebKit { | 44 namespace WebKit { |
44 | 45 |
45 class WebCString; | 46 class WebCString; |
46 class WebStringPrivate; | 47 class WebStringPrivate; |
47 | 48 |
48 // A UTF-16 string container. It is inexpensive to copy a WebString | 49 // A UTF-16 string container. It is inexpensive to copy a WebString |
49 // object. | 50 // object. |
50 // | 51 // |
(...skipping 18 matching lines...) Expand all Loading... |
69 return *this; | 70 return *this; |
70 } | 71 } |
71 | 72 |
72 WEBKIT_EXPORT void reset(); | 73 WEBKIT_EXPORT void reset(); |
73 WEBKIT_EXPORT void assign(const WebString&); | 74 WEBKIT_EXPORT void assign(const WebString&); |
74 WEBKIT_EXPORT void assign(const WebUChar* data, size_t len); | 75 WEBKIT_EXPORT void assign(const WebUChar* data, size_t len); |
75 | 76 |
76 WEBKIT_EXPORT bool equals(const WebString& s) const; | 77 WEBKIT_EXPORT bool equals(const WebString& s) const; |
77 | 78 |
78 WEBKIT_EXPORT size_t length() const; | 79 WEBKIT_EXPORT size_t length() const; |
| 80 // Deprecated: This function will be removed once all its callers are gone. |
79 WEBKIT_EXPORT const WebUChar* data() const; | 81 WEBKIT_EXPORT const WebUChar* data() const; |
80 | 82 |
81 // Caller must check bounds. | 83 // Caller must check bounds. |
82 WEBKIT_EXPORT WebUChar at(unsigned) const; | 84 WEBKIT_EXPORT WebUChar at(unsigned) const; |
83 | 85 |
84 bool isEmpty() const { return !length(); } | 86 bool isEmpty() const { return !length(); } |
85 bool isNull() const { return !m_private; } | 87 bool isNull() const { return !m_private; } |
86 | 88 |
87 WEBKIT_EXPORT WebCString utf8() const; | 89 WEBKIT_EXPORT WebCString utf8() const; |
88 | 90 |
(...skipping 28 matching lines...) Expand all Loading... |
117 } | 119 } |
118 | 120 |
119 WebString& operator=(const string16& s) | 121 WebString& operator=(const string16& s) |
120 { | 122 { |
121 assign(s.data(), s.length()); | 123 assign(s.data(), s.length()); |
122 return *this; | 124 return *this; |
123 } | 125 } |
124 | 126 |
125 operator string16() const | 127 operator string16() const |
126 { | 128 { |
127 size_t len = length(); | 129 return base::Latin1OrUTF16ToUTF16(length(), data8(), data16()); |
128 return len ? string16(data(), len) : string16(); | |
129 } | 130 } |
130 | 131 |
131 WebString(const NullableString16& s) : m_private(0) | 132 WebString(const NullableString16& s) : m_private(0) |
132 { | 133 { |
133 if (s.is_null()) | 134 if (s.is_null()) |
134 reset(); | 135 reset(); |
135 else | 136 else |
136 assign(s.string().data(), s.string().length()); | 137 assign(s.string().data(), s.string().length()); |
137 } | 138 } |
138 | 139 |
139 WebString& operator=(const NullableString16& s) | 140 WebString& operator=(const NullableString16& s) |
140 { | 141 { |
141 if (s.is_null()) | 142 if (s.is_null()) |
142 reset(); | 143 reset(); |
143 else | 144 else |
144 assign(s.string().data(), s.string().length()); | 145 assign(s.string().data(), s.string().length()); |
145 return *this; | 146 return *this; |
146 } | 147 } |
147 | 148 |
148 operator NullableString16() const | 149 operator NullableString16() const |
149 { | 150 { |
150 if (!m_private) | 151 return NullableString16(operator string16(), !m_private); |
151 return NullableString16(string16(), true); | |
152 size_t len = length(); | |
153 return NullableString16(len ? string16(data(), len) : string16(), false)
; | |
154 } | 152 } |
155 | 153 |
156 template <class UTF8String> | 154 template <class UTF8String> |
157 static WebString fromUTF8(const UTF8String& s) | 155 static WebString fromUTF8(const UTF8String& s) |
158 { | 156 { |
159 return fromUTF8(s.data(), s.length()); | 157 return fromUTF8(s.data(), s.length()); |
160 } | 158 } |
161 #endif | 159 #endif |
162 | 160 |
163 private: | 161 private: |
| 162 WEBKIT_EXPORT bool is8Bit() const; |
| 163 WEBKIT_EXPORT const WebLChar* data8() const; |
| 164 WEBKIT_EXPORT const WebUChar* data16() const; |
| 165 |
164 void assign(WebStringPrivate*); | 166 void assign(WebStringPrivate*); |
165 | 167 |
166 WebStringPrivate* m_private; | 168 WebStringPrivate* m_private; |
167 }; | 169 }; |
168 | 170 |
169 inline bool operator==(const WebString& a, const WebString& b) | 171 inline bool operator==(const WebString& a, const WebString& b) |
170 { | 172 { |
171 return a.equals(b); | 173 return a.equals(b); |
172 } | 174 } |
173 | 175 |
174 inline bool operator!=(const WebString& a, const WebString& b) | 176 inline bool operator!=(const WebString& a, const WebString& b) |
175 { | 177 { |
176 return !(a == b); | 178 return !(a == b); |
177 } | 179 } |
178 | 180 |
179 } // namespace WebKit | 181 } // namespace WebKit |
180 | 182 |
181 #endif | 183 #endif |
OLD | NEW |