| 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 #include "config.h" | |
| 32 #include "WebString.h" | |
| 33 | |
| 34 #include "AtomicString.h" | |
| 35 #include "CString.h" | |
| 36 #include "PlatformString.h" | |
| 37 | |
| 38 #include "WebCString.h" | |
| 39 | |
| 40 namespace WebKit { | |
| 41 | |
| 42 class WebStringPrivate : public WebCore::StringImpl { | |
| 43 }; | |
| 44 | |
| 45 void WebString::reset() | |
| 46 { | |
| 47 if (m_private) { | |
| 48 m_private->deref(); | |
| 49 m_private = 0; | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void WebString::assign(const WebString& other) | |
| 54 { | |
| 55 assign(const_cast<WebStringPrivate*>(other.m_private)); | |
| 56 } | |
| 57 | |
| 58 void WebString::assign(const WebUChar* data, size_t length) | |
| 59 { | |
| 60 assign(static_cast<WebStringPrivate*>( | |
| 61 WebCore::StringImpl::create(data, length).get())); | |
| 62 } | |
| 63 | |
| 64 size_t WebString::length() const | |
| 65 { | |
| 66 return m_private ? const_cast<WebStringPrivate*>(m_private)->length() : 0; | |
| 67 } | |
| 68 | |
| 69 const WebUChar* WebString::data() const | |
| 70 { | |
| 71 return m_private ? const_cast<WebStringPrivate*>(m_private)->characters() : 0; | |
| 72 } | |
| 73 | |
| 74 WebCString WebString::utf8() const | |
| 75 { | |
| 76 return WebCore::String(m_private).utf8(); | |
| 77 } | |
| 78 | |
| 79 WebString WebString::fromUTF8(const char* data, size_t length) | |
| 80 { | |
| 81 return WebCore::String::fromUTF8(data, length); | |
| 82 } | |
| 83 | |
| 84 WebString WebString::fromUTF8(const char* data) | |
| 85 { | |
| 86 return WebCore::String::fromUTF8(data); | |
| 87 } | |
| 88 | |
| 89 WebString::WebString(const WebCore::String& s) | |
| 90 : m_private(static_cast<WebStringPrivate*>(s.impl())) | |
| 91 { | |
| 92 if (m_private) | |
| 93 m_private->ref(); | |
| 94 } | |
| 95 | |
| 96 WebString& WebString::operator=(const WebCore::String& s) | |
| 97 { | |
| 98 assign(static_cast<WebStringPrivate*>(s.impl())); | |
| 99 return *this; | |
| 100 } | |
| 101 | |
| 102 WebString::operator WebCore::String() const | |
| 103 { | |
| 104 return m_private; | |
| 105 } | |
| 106 | |
| 107 WebString::WebString(const WebCore::AtomicString& s) | |
| 108 : m_private(0) | |
| 109 { | |
| 110 assign(s.string()); | |
| 111 } | |
| 112 | |
| 113 WebString& WebString::operator=(const WebCore::AtomicString& s) | |
| 114 { | |
| 115 assign(s.string()); | |
| 116 return *this; | |
| 117 } | |
| 118 | |
| 119 WebString::operator WebCore::AtomicString() const | |
| 120 { | |
| 121 return WebCore::AtomicString(static_cast<WebCore::StringImpl *>(m_private)); | |
| 122 } | |
| 123 | |
| 124 void WebString::assign(WebStringPrivate* p) | |
| 125 { | |
| 126 // Take care to handle the case where m_private == p | |
| 127 if (p) | |
| 128 p->ref(); | |
| 129 if (m_private) | |
| 130 m_private->deref(); | |
| 131 m_private = p; | |
| 132 } | |
| 133 | |
| 134 } // namespace WebKit | |
| OLD | NEW |