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 18 matching lines...) Expand all Loading... |
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 "WebCommon.h" |
35 | 35 |
36 #if WEBKIT_IMPLEMENTATION | 36 #if WEBKIT_IMPLEMENTATION |
37 namespace WebCore { class String; class AtomicString; } | 37 namespace WebCore { class String; class AtomicString; } |
38 #else | 38 #else |
| 39 #include <base/nullable_string16.h> |
39 #include <base/string16.h> | 40 #include <base/string16.h> |
40 #endif | 41 #endif |
41 | 42 |
42 namespace WebKit { | 43 namespace WebKit { |
43 class WebCString; | 44 class WebCString; |
44 class WebStringPrivate; | 45 class WebStringPrivate; |
45 | 46 |
46 // A UTF-16 string container. It is inexpensive to copy a WebString | 47 // A UTF-16 string container. It is inexpensive to copy a WebString |
47 // object. | 48 // object. |
48 // | 49 // |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 assign(s.data(), s.length()); | 102 assign(s.data(), s.length()); |
102 return *this; | 103 return *this; |
103 } | 104 } |
104 | 105 |
105 operator string16() const | 106 operator string16() const |
106 { | 107 { |
107 size_t len = length(); | 108 size_t len = length(); |
108 return len ? string16(data(), len) : string16(); | 109 return len ? string16(data(), len) : string16(); |
109 } | 110 } |
110 | 111 |
| 112 WebString(const NullableString16& s) : m_private(0) |
| 113 { |
| 114 if (s.is_null()) |
| 115 assign(0); |
| 116 else |
| 117 assign(s.string().data(), s.string().length()); |
| 118 } |
| 119 |
| 120 WebString& operator=(const NullableString16& s) |
| 121 { |
| 122 if (s.is_null()) |
| 123 assign(0); |
| 124 else |
| 125 assign(s.string().data(), s.string().length()); |
| 126 return *this; |
| 127 } |
| 128 |
| 129 operator NullableString16() const |
| 130 { |
| 131 if (!m_private) |
| 132 return NullableString16(string16(), true); |
| 133 size_t len = length(); |
| 134 return NullableString16(len ? string16(data(), len) : string16(), false); |
| 135 } |
| 136 |
111 template <class UTF8String> | 137 template <class UTF8String> |
112 static WebString fromUTF8(const UTF8String& s) | 138 static WebString fromUTF8(const UTF8String& s) |
113 { | 139 { |
114 return fromUTF8(s.data(), s.length()); | 140 return fromUTF8(s.data(), s.length()); |
115 } | 141 } |
116 #endif | 142 #endif |
117 | 143 |
118 private: | 144 private: |
119 void assign(WebStringPrivate*); | 145 void assign(WebStringPrivate*); |
120 WebStringPrivate* m_private; | 146 WebStringPrivate* m_private; |
121 }; | 147 }; |
122 | 148 |
123 } // namespace WebKit | 149 } // namespace WebKit |
124 | 150 |
125 #endif | 151 #endif |
OLD | NEW |