| 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 15 matching lines...) Expand all Loading... |
| 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 "WebCommon.h" |
| 35 #include "WebPrivatePtr.h" | 35 #include "WebPrivatePtr.h" |
| 36 #include "base/strings/latin1_string_conversions.h" |
| 37 #include "base/strings/nullable_string16.h" |
| 38 #include "base/strings/string16.h" |
| 36 #include <string> | 39 #include <string> |
| 37 | 40 |
| 38 #if INSIDE_BLINK | 41 #if INSIDE_BLINK |
| 39 #include "wtf/Forward.h" | 42 #include "wtf/Forward.h" |
| 40 #else | |
| 41 #include <base/strings/latin1_string_conversions.h> | |
| 42 #include <base/strings/nullable_string16.h> | |
| 43 #include <base/strings/string16.h> | |
| 44 #endif | 43 #endif |
| 45 | 44 |
| 46 namespace WTF { | 45 namespace WTF { |
| 47 class StringImpl; | 46 class StringImpl; |
| 48 } | 47 } |
| 49 | 48 |
| 50 namespace blink { | 49 namespace blink { |
| 51 | 50 |
| 52 // A UTF-16 string container. It is inexpensive to copy a WebString | 51 // Use either one of static methods to convert ASCII, Latin1, UTF-8 or |
| 53 // object. | 52 // UTF-16 string into WebString: |
| 54 // | 53 // |
| 54 // * WebString::fromASCII(const std::string& ascii) |
| 55 // * WebString::fromLatin1(const std::string& latin1) |
| 56 // * WebString::fromUTF8(const std::string& utf8) |
| 57 // * WebString::fromUTF16(const base::string16& utf16) |
| 58 // * WebString::fromUTF16(const base::NullableString16& utf16) |
| 59 // |
| 60 // Similarly, use either of following methods to convert WebString to |
| 61 // ASCII, Latin1, UTF-8 or UTF-16: |
| 62 // |
| 63 // * webstring.ascii() |
| 64 // * webstring.latin1() |
| 65 // * webstring.utf8() |
| 66 // * webstring.utf16() |
| 67 // * WebString::toNullableString16(webstring) |
| 68 // |
| 69 // Some types like GURL and base::FilePath can directly take either utf-8 or |
| 70 // utf-16 strings. Use following methods to convert WebString to/from GURL or |
| 71 // FilePath rather than going through intermediate string types: |
| 72 // |
| 73 // * GURL WebStringToGURL(const WebString&) |
| 74 // * base::FilePath WebStringToFilePath(const WebString&) |
| 75 // * WebString FilePathToWebString(const base::FilePath&) |
| 76 // |
| 77 // Also see helper templates defined in StringVectorCopier.h for |
| 78 // string vector conversions (like std::vector<base::string16> to |
| 79 // WebVector<WebString). |
| 80 // |
| 81 // It is inexpensive to copy a WebString object. |
| 55 // WARNING: It is not safe to pass a WebString across threads!!! | 82 // WARNING: It is not safe to pass a WebString across threads!!! |
| 56 // | 83 // |
| 57 class WebString { | 84 class WebString { |
| 58 public: | 85 public: |
| 59 ~WebString() { reset(); } | 86 ~WebString() { reset(); } |
| 60 | 87 |
| 61 WebString() {} | 88 WebString() {} |
| 62 | 89 |
| 63 WebString(const WebUChar* data, size_t len) { assign(data, len); } | 90 WebString(const WebUChar* data, size_t len) { assign(data, len); } |
| 64 | 91 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 BLINK_COMMON_EXPORT std::string utf8() const; | 111 BLINK_COMMON_EXPORT std::string utf8() const; |
| 85 | 112 |
| 86 BLINK_COMMON_EXPORT static WebString fromUTF8(const char* data, | 113 BLINK_COMMON_EXPORT static WebString fromUTF8(const char* data, |
| 87 size_t length); | 114 size_t length); |
| 88 BLINK_COMMON_EXPORT static WebString fromUTF8(const char* data); | 115 BLINK_COMMON_EXPORT static WebString fromUTF8(const char* data); |
| 89 | 116 |
| 90 static WebString fromUTF8(const std::string& s) { | 117 static WebString fromUTF8(const std::string& s) { |
| 91 return fromUTF8(s.data(), s.length()); | 118 return fromUTF8(s.data(), s.length()); |
| 92 } | 119 } |
| 93 | 120 |
| 121 base::string16 utf16() const { |
| 122 return base::Latin1OrUTF16ToUTF16(length(), data8(), data16()); |
| 123 } |
| 124 |
| 125 BLINK_COMMON_EXPORT static WebString fromUTF16(const base::string16&); |
| 126 |
| 127 BLINK_COMMON_EXPORT static WebString fromUTF16(const base::NullableString16&); |
| 128 |
| 129 static base::NullableString16 toNullableString16(const WebString& s) { |
| 130 return base::NullableString16(s.utf16(), s.isNull()); |
| 131 } |
| 132 |
| 94 BLINK_COMMON_EXPORT std::string latin1() const; | 133 BLINK_COMMON_EXPORT std::string latin1() const; |
| 95 | 134 |
| 96 BLINK_COMMON_EXPORT static WebString fromLatin1(const WebLChar* data, | 135 BLINK_COMMON_EXPORT static WebString fromLatin1(const WebLChar* data, |
| 97 size_t length); | 136 size_t length); |
| 98 | 137 |
| 99 static WebString fromLatin1(const std::string& s) { | 138 static WebString fromLatin1(const std::string& s) { |
| 100 return fromLatin1(reinterpret_cast<const WebLChar*>(s.data()), s.length()); | 139 return fromLatin1(reinterpret_cast<const WebLChar*>(s.data()), s.length()); |
| 101 } | 140 } |
| 102 | 141 |
| 103 // This asserts if the string contains non-ascii characters. | 142 // This asserts if the string contains non-ascii characters. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 BLINK_COMMON_EXPORT WebString(const WTF::String&); | 165 BLINK_COMMON_EXPORT WebString(const WTF::String&); |
| 127 BLINK_COMMON_EXPORT WebString& operator=(const WTF::String&); | 166 BLINK_COMMON_EXPORT WebString& operator=(const WTF::String&); |
| 128 BLINK_COMMON_EXPORT operator WTF::String() const; | 167 BLINK_COMMON_EXPORT operator WTF::String() const; |
| 129 | 168 |
| 130 BLINK_COMMON_EXPORT operator WTF::StringView() const; | 169 BLINK_COMMON_EXPORT operator WTF::StringView() const; |
| 131 | 170 |
| 132 BLINK_COMMON_EXPORT WebString(const WTF::AtomicString&); | 171 BLINK_COMMON_EXPORT WebString(const WTF::AtomicString&); |
| 133 BLINK_COMMON_EXPORT WebString& operator=(const WTF::AtomicString&); | 172 BLINK_COMMON_EXPORT WebString& operator=(const WTF::AtomicString&); |
| 134 BLINK_COMMON_EXPORT operator WTF::AtomicString() const; | 173 BLINK_COMMON_EXPORT operator WTF::AtomicString() const; |
| 135 #else | 174 #else |
| 175 // WARNING: implicit conversions to/from string16 are being deprecated, |
| 176 // use fromUTF16() or utf16() instead in new changes. |
| 136 WebString(const base::string16& s) { assign(s.data(), s.length()); } | 177 WebString(const base::string16& s) { assign(s.data(), s.length()); } |
| 137 | 178 |
| 138 WebString& operator=(const base::string16& s) { | 179 WebString& operator=(const base::string16& s) { |
| 139 assign(s.data(), s.length()); | 180 assign(s.data(), s.length()); |
| 140 return *this; | 181 return *this; |
| 141 } | 182 } |
| 142 | 183 |
| 143 operator base::string16() const { | 184 operator base::string16() const { |
| 144 return base::Latin1OrUTF16ToUTF16(length(), data8(), data16()); | 185 return base::Latin1OrUTF16ToUTF16(length(), data8(), data16()); |
| 145 } | 186 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return a.equals(b); | 236 return a.equals(b); |
| 196 } | 237 } |
| 197 | 238 |
| 198 inline bool operator!=(const WebString& a, const WebString& b) { | 239 inline bool operator!=(const WebString& a, const WebString& b) { |
| 199 return !(a == b); | 240 return !(a == b); |
| 200 } | 241 } |
| 201 | 242 |
| 202 } // namespace blink | 243 } // namespace blink |
| 203 | 244 |
| 204 #endif | 245 #endif |
| OLD | NEW |