2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "WebDOMString.h"
24 #include "WebDOMCString.h"
25 #include <wtf/text/AtomicString.h>
26 #include <wtf/text/CString.h>
27 #include <wtf/text/WTFString.h>
29 class WebDOMStringPrivate : public WTF::StringImpl {
32 void WebDOMString::reset()
40 void WebDOMString::assign(const WebDOMString& other)
42 assign(const_cast<WebDOMStringPrivate*>(other.m_private));
45 void WebDOMString::assign(const WebUChar* data, size_t length)
47 assign(static_cast<WebDOMStringPrivate*>(
48 WTF::StringImpl::create(data, length).get()));
51 size_t WebDOMString::length() const
53 return m_private ? const_cast<WebDOMStringPrivate*>(m_private)->length() : 0;
56 const WebUChar* WebDOMString::data() const
58 return m_private ? const_cast<WebDOMStringPrivate*>(m_private)->characters() : 0;
61 WebDOMCString WebDOMString::utf8() const
63 return WTF::String(m_private).utf8();
66 WebDOMString WebDOMString::fromUTF8(const char* data, size_t length)
68 return WTF::String::fromUTF8(data, length);
71 WebDOMString WebDOMString::fromUTF8(const char* data)
73 return WTF::String::fromUTF8(data);
76 WebDOMString::WebDOMString(const WTF::String& s)
77 : m_private(static_cast<WebDOMStringPrivate*>(s.impl()))
83 WebDOMString& WebDOMString::operator=(const WTF::String& s)
85 assign(static_cast<WebDOMStringPrivate*>(s.impl()));
89 WebDOMString::operator WTF::String() const
94 WebDOMString::WebDOMString(const WTF::AtomicString& s)
100 WebDOMString& WebDOMString::operator=(const WTF::AtomicString& s)
106 WebDOMString::operator WTF::AtomicString() const
108 return WTF::AtomicString(static_cast<WTF::StringImpl *>(m_private));
111 bool WebDOMString::equals(const char* string) const
113 return WTF::equal(m_private, string);
116 void WebDOMString::assign(WebDOMStringPrivate* p)
118 // Take care to handle the case where m_private == p