| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #ifndef WebString_h | |
| 32 #define WebString_h | |
| 33 | |
| 34 #include "WebCommon.h" | |
| 35 | |
| 36 #if WEBKIT_IMPLEMENTATION | |
| 37 namespace WebCore { | |
| 38 class String; | |
| 39 class AtomicString; | |
| 40 } | |
| 41 #else | |
| 42 #include <base/nullable_string16.h> | |
| 43 #include <base/string16.h> | |
| 44 #endif | |
| 45 | |
| 46 namespace WebKit { | |
| 47 | |
| 48 class WebCString; | |
| 49 class WebStringPrivate; | |
| 50 | |
| 51 // A UTF-16 string container. It is inexpensive to copy a WebString | |
| 52 // object. | |
| 53 // | |
| 54 // WARNING: It is not safe to pass a WebString across threads!!! | |
| 55 // | |
| 56 class WebString { | |
| 57 public: | |
| 58 ~WebString() { reset(); } | |
| 59 | |
| 60 WebString() : m_private(0) { } | |
| 61 | |
| 62 WebString(const WebUChar* data, size_t len) : m_private(0) | |
| 63 { | |
| 64 assign(data, len); | |
| 65 } | |
| 66 | |
| 67 WebString(const WebString& s) : m_private(0) { assign(s); } | |
| 68 | |
| 69 WebString& operator=(const WebString& s) | |
| 70 { | |
| 71 assign(s); | |
| 72 return *this; | |
| 73 } | |
| 74 | |
| 75 WEBKIT_API void reset(); | |
| 76 WEBKIT_API void assign(const WebString&); | |
| 77 WEBKIT_API void assign(const WebUChar* data, size_t len); | |
| 78 | |
| 79 WEBKIT_API size_t length() const; | |
| 80 WEBKIT_API const WebUChar* data() const; | |
| 81 | |
| 82 bool isEmpty() const { return !length(); } | |
| 83 bool isNull() const { return !m_private; } | |
| 84 | |
| 85 WEBKIT_API WebCString utf8() const; | |
| 86 | |
| 87 WEBKIT_API static WebString fromUTF8(const char* data, size_t length); | |
| 88 WEBKIT_API static WebString fromUTF8(const char* data); | |
| 89 | |
| 90 #if WEBKIT_IMPLEMENTATION | |
| 91 WebString(const WebCore::String&); | |
| 92 WebString& operator=(const WebCore::String&); | |
| 93 operator WebCore::String() const; | |
| 94 | |
| 95 WebString(const WebCore::AtomicString&); | |
| 96 WebString& operator=(const WebCore::AtomicString&); | |
| 97 operator WebCore::AtomicString() const; | |
| 98 #else | |
| 99 WebString(const string16& s) : m_private(0) | |
| 100 { | |
| 101 assign(s.data(), s.length()); | |
| 102 } | |
| 103 | |
| 104 WebString& operator=(const string16& s) | |
| 105 { | |
| 106 assign(s.data(), s.length()); | |
| 107 return *this; | |
| 108 } | |
| 109 | |
| 110 operator string16() const | |
| 111 { | |
| 112 size_t len = length(); | |
| 113 return len ? string16(data(), len) : string16(); | |
| 114 } | |
| 115 | |
| 116 WebString(const NullableString16& s) : m_private(0) | |
| 117 { | |
| 118 if (s.is_null()) | |
| 119 assign(0); | |
| 120 else | |
| 121 assign(s.string().data(), s.string().length()); | |
| 122 } | |
| 123 | |
| 124 WebString& operator=(const NullableString16& s) | |
| 125 { | |
| 126 if (s.is_null()) | |
| 127 assign(0); | |
| 128 else | |
| 129 assign(s.string().data(), s.string().length()); | |
| 130 return *this; | |
| 131 } | |
| 132 | |
| 133 operator NullableString16() const | |
| 134 { | |
| 135 if (!m_private) | |
| 136 return NullableString16(string16(), true); | |
| 137 size_t len = length(); | |
| 138 return NullableString16(len ? string16(data(), len) : string16(), false); | |
| 139 } | |
| 140 | |
| 141 template <class UTF8String> | |
| 142 static WebString fromUTF8(const UTF8String& s) | |
| 143 { | |
| 144 return fromUTF8(s.data(), s.length()); | |
| 145 } | |
| 146 #endif | |
| 147 | |
| 148 private: | |
| 149 void assign(WebStringPrivate*); | |
| 150 WebStringPrivate* m_private; | |
| 151 }; | |
| 152 | |
| 153 } // namespace WebKit | |
| 154 | |
| 155 #endif | |
| OLD | NEW |