summaryrefslogtreecommitdiffstats
path: root/src/script/api
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-02 17:01:13 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-02 17:01:13 (GMT)
commit20cfe1e790295254370cf472df39813f864de7ea (patch)
tree98ac008f7c468ed37a61c051870810db2bbf2360 /src/script/api
parent83e497fdae56e11c79d913cdc665e78615291e9c (diff)
parent2ed925753cb194970712330edca4da8e91fa8f28 (diff)
downloadQt-20cfe1e790295254370cf472df39813f864de7ea.zip
Qt-20cfe1e790295254370cf472df39813f864de7ea.tar.gz
Qt-20cfe1e790295254370cf472df39813f864de7ea.tar.bz2
Merge remote branch 'mainline/4.6' into 4.6
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/qscriptstring.cpp29
-rw-r--r--src/script/api/qscriptstring.h2
2 files changed, 31 insertions, 0 deletions
diff --git a/src/script/api/qscriptstring.cpp b/src/script/api/qscriptstring.cpp
index 1ede51c..10fccd0 100644
--- a/src/script/api/qscriptstring.cpp
+++ b/src/script/api/qscriptstring.cpp
@@ -68,6 +68,10 @@ QT_BEGIN_NAMESPACE
Call the toString() function to obtain the string that a
QScriptString represents.
+
+ Call the toArrayIndex() function to convert a QScriptString to an
+ array index. This is useful when using QScriptClass to implement
+ array-like objects.
*/
/*!
@@ -164,6 +168,31 @@ bool QScriptString::operator!=(const QScriptString &other) const
}
/*!
+ \since 4.6
+
+ Attempts to convert this QScriptString to a QtScript array index,
+ and returns the result.
+
+ If a conversion error occurs, *\a{ok} is set to false; otherwise
+ *\a{ok} is set to true.
+*/
+quint32 QScriptString::toArrayIndex(bool *ok) const
+{
+ Q_D(const QScriptString);
+ if (!d) {
+ if (ok)
+ *ok = false;
+ return -1;
+ }
+ bool tmp;
+ bool *okok = ok ? ok : &tmp;
+ quint32 result = d->identifier.toArrayIndex(okok);
+ if (!*okok)
+ result = -1;
+ return result;
+}
+
+/*!
Returns the string that this QScriptString represents, or a
null string if this QScriptString is not valid.
diff --git a/src/script/api/qscriptstring.h b/src/script/api/qscriptstring.h
index 40d156c..bf5d1d5 100644
--- a/src/script/api/qscriptstring.h
+++ b/src/script/api/qscriptstring.h
@@ -67,6 +67,8 @@ public:
bool operator==(const QScriptString &other) const;
bool operator!=(const QScriptString &other) const;
+ quint32 toArrayIndex(bool *ok = 0) const;
+
QString toString() const;
operator QString() const;