]>
git.saurik.com Git - apple/javascriptcore.git/blob - qt/api/qscriptstring_p.h
2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef qscriptstring_p_h
21 #define qscriptstring_p_h
23 #include "qscriptconverter_p.h"
24 #include "qscriptstring.h"
25 #include <JavaScriptCore/JavaScript.h>
26 #include <QtCore/qnumeric.h>
27 #include <QtCore/qshareddata.h>
29 class QScriptStringPrivate
: public QSharedData
{
31 inline QScriptStringPrivate();
32 inline QScriptStringPrivate(const QString
& qtstring
);
33 inline ~QScriptStringPrivate();
35 static inline QScriptString
get(QScriptStringPrivate
* d
);
36 static inline QScriptStringPtr
get(const QScriptString
& p
);
38 inline bool isValid() const;
40 inline bool operator==(const QScriptStringPrivate
& other
) const;
41 inline bool operator!=(const QScriptStringPrivate
& other
) const;
43 inline quint32
toArrayIndex(bool* ok
= 0) const;
45 inline QString
toString() const;
47 inline quint64
id() const;
49 inline operator JSStringRef() const;
56 QScriptStringPrivate::QScriptStringPrivate()
60 QScriptStringPrivate::QScriptStringPrivate(const QString
& qtstring
)
61 : m_string(QScriptConverter::toString(qtstring
))
64 QScriptStringPrivate::~QScriptStringPrivate()
67 JSStringRelease(m_string
);
70 QScriptString
QScriptStringPrivate::get(QScriptStringPrivate
* d
)
73 return QScriptString(d
);
76 QScriptStringPtr
QScriptStringPrivate::get(const QScriptString
& p
)
81 bool QScriptStringPrivate::isValid() const
86 bool QScriptStringPrivate::operator==(const QScriptStringPrivate
& other
) const
88 return isValid() && other
.isValid() && JSStringIsEqual(m_string
, other
.m_string
);
91 bool QScriptStringPrivate::operator!=(const QScriptStringPrivate
& other
) const
93 return isValid() && other
.isValid() && !JSStringIsEqual(m_string
, other
.m_string
);
96 quint32
QScriptStringPrivate::toArrayIndex(bool* ok
) const
98 quint32 idx
= QScriptConverter::toArrayIndex(m_string
);
100 *ok
= (idx
!= 0xffffffff);
104 QString
QScriptStringPrivate::toString() const
106 return QScriptConverter::toString(m_string
);
109 quint64
QScriptStringPrivate::id() const
111 return reinterpret_cast<quint32
>(m_string
);
116 This method should be used for invoking JSC functions.
117 \note This method keeps ownership of an internal JSStringRef.
119 QScriptStringPrivate::operator JSStringRef() const
124 #endif // qscriptstring_p_h