| 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 "public/platform/WebString.h" | |
| 33 | |
| 34 #include "public/platform/WebCString.h" | |
| 35 #include <wtf/text/AtomicString.h> | |
| 36 #include <wtf/text/CString.h> | |
| 37 #include <wtf/text/WTFString.h> | |
| 38 | |
| 39 namespace WebKit { | |
| 40 | |
| 41 void WebString::reset() | |
| 42 { | |
| 43 m_private.reset(); | |
| 44 } | |
| 45 | |
| 46 void WebString::assign(const WebString& other) | |
| 47 { | |
| 48 assign(other.m_private.get()); | |
| 49 } | |
| 50 | |
| 51 void WebString::assign(const WebUChar* data, size_t length) | |
| 52 { | |
| 53 assign(StringImpl::create8BitIfPossible(data, length).get()); | |
| 54 } | |
| 55 | |
| 56 size_t WebString::length() const | |
| 57 { | |
| 58 return m_private.isNull() ? 0 : m_private->length(); | |
| 59 } | |
| 60 | |
| 61 WebUChar WebString::at(unsigned i) const | |
| 62 { | |
| 63 ASSERT(!m_private.isNull()); | |
| 64 return (*m_private.get())[i]; | |
| 65 } | |
| 66 | |
| 67 bool WebString::is8Bit() const | |
| 68 { | |
| 69 return m_private->is8Bit(); | |
| 70 } | |
| 71 | |
| 72 const WebLChar* WebString::data8() const | |
| 73 { | |
| 74 return !m_private.isNull() && is8Bit() ? m_private->characters8() : 0; | |
| 75 } | |
| 76 | |
| 77 const WebUChar* WebString::data16() const | |
| 78 { | |
| 79 return !m_private.isNull() && !is8Bit() ? m_private->characters16() : 0; | |
| 80 } | |
| 81 | |
| 82 WebCString WebString::utf8() const | |
| 83 { | |
| 84 return WTF::String(m_private.get()).utf8(); | |
| 85 } | |
| 86 | |
| 87 WebString WebString::fromUTF8(const char* data, size_t length) | |
| 88 { | |
| 89 return WTF::String::fromUTF8(data, length); | |
| 90 } | |
| 91 | |
| 92 WebString WebString::fromUTF8(const char* data) | |
| 93 { | |
| 94 return WTF::String::fromUTF8(data); | |
| 95 } | |
| 96 | |
| 97 bool WebString::equals(const WebString& s) const | |
| 98 { | |
| 99 return equal(m_private.get(), s.m_private.get()); | |
| 100 } | |
| 101 | |
| 102 WebString::WebString(const WTF::String& s) | |
| 103 { | |
| 104 m_private = s.impl(); | |
| 105 } | |
| 106 | |
| 107 WebString& WebString::operator=(const WTF::String& s) | |
| 108 { | |
| 109 assign(s.impl()); | |
| 110 return *this; | |
| 111 } | |
| 112 | |
| 113 WebString::operator WTF::String() const | |
| 114 { | |
| 115 return m_private.get(); | |
| 116 } | |
| 117 | |
| 118 WebString::WebString(const WTF::AtomicString& s) | |
| 119 { | |
| 120 assign(s.string()); | |
| 121 } | |
| 122 | |
| 123 WebString& WebString::operator=(const WTF::AtomicString& s) | |
| 124 { | |
| 125 assign(s.string()); | |
| 126 return *this; | |
| 127 } | |
| 128 | |
| 129 WebString::operator WTF::AtomicString() const | |
| 130 { | |
| 131 return WTF::AtomicString(m_private.get()); | |
| 132 } | |
| 133 | |
| 134 void WebString::assign(WTF::StringImpl* p) | |
| 135 { | |
| 136 m_private = p; | |
| 137 } | |
| 138 | |
| 139 } // namespace WebKit | |
| OLD | NEW |