blob: f4fd117fba2ec336164ec13bbc22d5676f8ac379 (
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
|
/*
Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef qscriptstring_p_h
#define qscriptstring_p_h
#include "qscriptconverter_p.h"
#include "qscriptstring.h"
#include <JavaScriptCore/JavaScript.h>
#include <QtCore/qnumeric.h>
#include <QtCore/qshareddata.h>
class QScriptStringPrivate : public QSharedData {
public:
inline QScriptStringPrivate();
inline QScriptStringPrivate(const QString& qtstring);
inline ~QScriptStringPrivate();
static inline QScriptString get(QScriptStringPrivate* d);
static inline QScriptStringPtr get(const QScriptString& p);
inline bool isValid() const;
inline bool operator==(const QScriptStringPrivate& other) const;
inline bool operator!=(const QScriptStringPrivate& other) const;
inline quint32 toArrayIndex(bool* ok = 0) const;
inline QString toString() const;
inline quint64 id() const;
private:
JSStringRef m_string;
};
QScriptStringPrivate::QScriptStringPrivate()
: m_string(0)
{}
QScriptStringPrivate::QScriptStringPrivate(const QString& qtstring)
: m_string(JSStringRetain(QScriptConverter::toString(qtstring)))
{}
QScriptStringPrivate::~QScriptStringPrivate()
{
if (isValid())
JSStringRelease(m_string);
}
QScriptString QScriptStringPrivate::get(QScriptStringPrivate* d)
{
Q_ASSERT(d);
return QScriptString(d);
}
QScriptStringPtr QScriptStringPrivate::get(const QScriptString& p)
{
return p.d_ptr;
}
bool QScriptStringPrivate::isValid() const
{
return m_string;
}
bool QScriptStringPrivate::operator==(const QScriptStringPrivate& other) const
{
return isValid() && other.isValid() && JSStringIsEqual(m_string, other.m_string);
}
bool QScriptStringPrivate::operator!=(const QScriptStringPrivate& other) const
{
return isValid() && other.isValid() && !JSStringIsEqual(m_string, other.m_string);
}
quint32 QScriptStringPrivate::toArrayIndex(bool* ok) const
{
quint32 idx = QScriptConverter::toArrayIndex(m_string);
if (ok)
*ok = (idx != 0xffffffff);
return idx;
}
QString QScriptStringPrivate::toString() const
{
return QScriptConverter::toString(m_string);
}
quint64 QScriptStringPrivate::id() const
{
return reinterpret_cast<quint32>(m_string);
}
#endif // qscriptstring_p_h
|