summaryrefslogtreecommitdiff
path: root/Source/WebKit/blackberry/Api/WebString.cpp
blob: 7429d86de43ac786f1d63b5344c53df52bb101b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2009, 2010, 2011 Research In Motion Limited. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"
#include "WebString.h"

#include "WebStringImpl.h"
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>

namespace BlackBerry {
namespace WebKit {

WebString::WebString(const char* latin1)
    : m_impl(static_cast<WebStringImpl*>(WTF::StringImpl::create(latin1).releaseRef()))
{
}

WebString::WebString(const char* latin1, unsigned length)
    : m_impl(static_cast<WebStringImpl*>(WTF::StringImpl::create(latin1, length).releaseRef()))
{
}

WebString::WebString(const unsigned short* utf16, unsigned length)
    : m_impl(static_cast<WebStringImpl*>(WTF::StringImpl::create(utf16, length).releaseRef()))
{
}

WebString::WebString(WebStringImpl* impl)
    : m_impl(impl)
{
    if (m_impl)
        m_impl->ref();
}

WebString::~WebString()
{
    if (m_impl)
        m_impl->deref();
}

WebString::WebString(const WebString& str)
    : m_impl(str.m_impl)
{
    if (m_impl)
        m_impl->ref();
}

WebString WebString::fromUtf8(const char* utf8)
{
    return String::fromUTF8(utf8);
}

WebString& WebString::operator=(const WebString& str)
{
    if (str.m_impl)
        str.m_impl->ref();
    if (m_impl)
        m_impl->deref();
    m_impl = str.m_impl;
    return *this;
}

std::string WebString::utf8() const
{
    std::string utf8;
    if (!m_impl)
        return utf8;

    CString cstr = String(m_impl).utf8();
    utf8.assign(cstr.data(), cstr.length());
    return utf8;
}

const unsigned short* WebString::characters() const
{
    return m_impl ? m_impl->characters() : 0;
}

unsigned WebString::length() const
{
    return m_impl ? m_impl->length() : 0;
}

bool WebString::isEmpty() const
{
    return !m_impl || !m_impl->length();
}

bool WebString::equal(const char* utf8) const
{
    return WTF::equal(m_impl, utf8);
}

bool WebString::equalIgnoringCase(const char* utf8) const
{
    return WTF::equalIgnoringCase(m_impl, utf8);
}

} // namespace WebKit
} // namespace BlackBerry