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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef WebString_h | 31 #ifndef WebString_h |
32 #define WebString_h | 32 #define WebString_h |
33 | 33 |
34 #include "WebCommon.h" | 34 #include "WebCommonExport.h" |
35 #include "WebPrivatePtr.h" | 35 #include "WebPrivatePtr.h" |
36 | 36 |
37 #if WEBKIT_IMPLEMENTATION | 37 #if !defined(INSIDE_WEBKIT) |
38 #include <wtf/Forward.h> | |
39 #else | |
40 #include <base/nullable_string16.h> | 38 #include <base/nullable_string16.h> |
41 #include <base/string16.h> | 39 #include <base/string16.h> |
42 #include <base/strings/latin1_string_conversions.h> | 40 #include <base/strings/latin1_string_conversions.h> |
43 #endif | 41 #endif |
44 | 42 |
45 namespace WTF { | 43 namespace WTF { |
| 44 class AtomicString; |
| 45 class String; |
46 class StringImpl; | 46 class StringImpl; |
47 } | 47 } |
48 | 48 |
49 namespace WebKit { | 49 namespace WebKit { |
50 | 50 |
| 51 // UTF-16 character type |
| 52 #if defined(WIN32) |
| 53 typedef wchar_t WebUChar; |
| 54 #else |
| 55 typedef unsigned short WebUChar; |
| 56 #endif |
| 57 |
| 58 // Latin-1 character type |
| 59 typedef unsigned char WebLChar; |
| 60 |
| 61 |
51 class WebCString; | 62 class WebCString; |
52 | 63 |
53 // A UTF-16 string container. It is inexpensive to copy a WebString | 64 // A UTF-16 string container. It is inexpensive to copy a WebString |
54 // object. | 65 // object. |
55 // | 66 // |
56 // WARNING: It is not safe to pass a WebString across threads!!! | 67 // WARNING: It is not safe to pass a WebString across threads!!! |
57 // | 68 // |
58 class WebString { | 69 class WebString { |
59 public: | 70 public: |
60 ~WebString() { reset(); } | 71 ~WebString() { reset(); } |
61 | 72 |
62 WebString() { } | 73 WebString() { } |
63 | 74 |
64 WebString(const WebUChar* data, size_t len) | 75 WebString(const WebUChar* data, size_t len) |
65 { | 76 { |
66 assign(data, len); | 77 assign(data, len); |
67 } | 78 } |
68 | 79 |
69 WebString(const WebString& s) { assign(s); } | 80 WebString(const WebString& s) { assign(s); } |
70 | 81 |
71 WebString& operator=(const WebString& s) | 82 WebString& operator=(const WebString& s) |
72 { | 83 { |
73 assign(s); | 84 assign(s); |
74 return *this; | 85 return *this; |
75 } | 86 } |
76 | 87 |
77 WEBKIT_EXPORT void reset(); | 88 BLINK_COMMON_EXPORT void reset(); |
78 WEBKIT_EXPORT void assign(const WebString&); | 89 BLINK_COMMON_EXPORT void assign(const WebString&); |
79 WEBKIT_EXPORT void assign(const WebUChar* data, size_t len); | 90 BLINK_COMMON_EXPORT void assign(const WebUChar* data, size_t len); |
80 | 91 |
81 WEBKIT_EXPORT bool equals(const WebString& s) const; | 92 BLINK_COMMON_EXPORT bool equals(const WebString&) const; |
82 | 93 |
83 WEBKIT_EXPORT size_t length() const; | 94 BLINK_COMMON_EXPORT size_t length() const; |
84 | 95 |
85 // Caller must check bounds. | 96 // Caller must check bounds. |
86 WEBKIT_EXPORT WebUChar at(unsigned) const; | 97 BLINK_COMMON_EXPORT WebUChar at(unsigned) const; |
87 | 98 |
88 bool isEmpty() const { return !length(); } | 99 bool isEmpty() const { return !length(); } |
89 bool isNull() const { return m_private.isNull(); } | 100 bool isNull() const { return m_private.isNull(); } |
90 | 101 |
91 WEBKIT_EXPORT WebCString utf8() const; | 102 BLINK_COMMON_EXPORT WebCString utf8() const; |
92 | 103 |
93 WEBKIT_EXPORT static WebString fromUTF8(const char* data, size_t length); | 104 BLINK_COMMON_EXPORT static WebString fromUTF8(const char* data, size_t lengt
h); |
94 WEBKIT_EXPORT static WebString fromUTF8(const char* data); | 105 BLINK_COMMON_EXPORT static WebString fromUTF8(const char* data); |
95 | 106 |
96 template <int N> WebString(const char (&data)[N]) | 107 template <int N> WebString(const char (&data)[N]) |
97 { | 108 { |
98 assign(fromUTF8(data, N - 1)); | 109 assign(fromUTF8(data, N - 1)); |
99 } | 110 } |
100 | 111 |
101 template <int N> WebString& operator=(const char (&data)[N]) | 112 template <int N> WebString& operator=(const char (&data)[N]) |
102 { | 113 { |
103 assign(fromUTF8(data, N - 1)); | 114 assign(fromUTF8(data, N - 1)); |
104 return *this; | 115 return *this; |
105 } | 116 } |
106 | 117 |
107 #if WEBKIT_IMPLEMENTATION | 118 #if defined(INSIDE_WEBKIT) |
108 WebString(const WTF::String&); | 119 BLINK_COMMON_EXPORT WebString(const WTF::String&); |
109 WebString& operator=(const WTF::String&); | 120 BLINK_COMMON_EXPORT WebString& operator=(const WTF::String&); |
110 operator WTF::String() const; | 121 BLINK_COMMON_EXPORT operator WTF::String() const; |
111 | 122 |
112 WebString(const WTF::AtomicString&); | 123 BLINK_COMMON_EXPORT WebString(const WTF::AtomicString&); |
113 WebString& operator=(const WTF::AtomicString&); | 124 BLINK_COMMON_EXPORT WebString& operator=(const WTF::AtomicString&); |
114 operator WTF::AtomicString() const; | 125 BLINK_COMMON_EXPORT operator WTF::AtomicString() const; |
115 #else | 126 #else |
116 | 127 |
117 WebString(const string16& s) | 128 WebString(const string16& s) |
118 { | 129 { |
119 assign(s.data(), s.length()); | 130 assign(s.data(), s.length()); |
120 } | 131 } |
121 | 132 |
122 WebString& operator=(const string16& s) | 133 WebString& operator=(const string16& s) |
123 { | 134 { |
124 assign(s.data(), s.length()); | 135 assign(s.data(), s.length()); |
(...skipping 28 matching lines...) Expand all Loading... |
153 } | 164 } |
154 | 165 |
155 template <class UTF8String> | 166 template <class UTF8String> |
156 static WebString fromUTF8(const UTF8String& s) | 167 static WebString fromUTF8(const UTF8String& s) |
157 { | 168 { |
158 return fromUTF8(s.data(), s.length()); | 169 return fromUTF8(s.data(), s.length()); |
159 } | 170 } |
160 #endif | 171 #endif |
161 | 172 |
162 private: | 173 private: |
163 WEBKIT_EXPORT bool is8Bit() const; | 174 BLINK_COMMON_EXPORT bool is8Bit() const; |
164 WEBKIT_EXPORT const WebLChar* data8() const; | 175 BLINK_COMMON_EXPORT const WebLChar* data8() const; |
165 WEBKIT_EXPORT const WebUChar* data16() const; | 176 BLINK_COMMON_EXPORT const WebUChar* data16() const; |
166 | 177 |
167 void assign(WTF::StringImpl*); | 178 void assign(WTF::StringImpl*); |
168 | 179 |
169 WebPrivatePtr<WTF::StringImpl> m_private; | 180 WebPrivatePtr<WTF::StringImpl> m_private; |
170 }; | 181 }; |
171 | 182 |
172 inline bool operator==(const WebString& a, const WebString& b) | 183 inline bool operator==(const WebString& a, const WebString& b) |
173 { | 184 { |
174 return a.equals(b); | 185 return a.equals(b); |
175 } | 186 } |
176 | 187 |
177 inline bool operator!=(const WebString& a, const WebString& b) | 188 inline bool operator!=(const WebString& a, const WebString& b) |
178 { | 189 { |
179 return !(a == b); | 190 return !(a == b); |
180 } | 191 } |
181 | 192 |
182 } // namespace WebKit | 193 } // namespace WebKit |
183 | 194 |
184 #endif | 195 #endif |
OLD | NEW |