Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4stringiterator.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 Crimson AS <info@crimson.no>
2// Copyright (C) 2018 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <private/qv4iterator_p.h>
6#include <private/qv4stringiterator_p.h>
7#include <private/qv4symbol_p.h>
8
9using namespace QV4;
10
12
21
23{
24 Scope scope(b);
25 const StringIteratorObject *thisObject = that->as<StringIteratorObject>();
26 if (!thisObject)
27 return scope.engine->throwTypeError(QLatin1String("Not an String Iterator instance"));
28
29 ScopedString s(scope, thisObject->d()->iteratedString);
30 if (!s) {
32 return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
33 }
34
35 quint32 index = thisObject->d()->nextIndex;
36
37 QString str = s->toQString();
38 quint32 len = str.size();
39
40 if (index >= len) {
41 thisObject->d()->iteratedString.set(scope.engine, nullptr);
43 return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
44 }
45
46 QChar ch = str.at(index);
47 int num = 1;
48 if (ch.unicode() >= 0xd800 && ch.unicode() <= 0xdbff && index + 1 != len) {
49 ch = str.at(index + 1);
50 if (ch.unicode() >= 0xdc00 && ch.unicode() <= 0xdfff)
51 num = 2;
52 }
53
54 thisObject->d()->nextIndex += num;
55
56 ScopedString resultString(scope, scope.engine->newString(s->toQString().mid(index, num)));
57 return IteratorPrototype::createIterResultObject(scope.engine, resultString, false);
58}
59
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
QString str
[2]
quint64 ReturnedValue
Scoped< String > ScopedString
GLboolean GLboolean GLboolean b
GLuint index
[2]
GLdouble s
[6]
Definition qopenglext.h:235
GLuint GLfloat * val
GLenum GLsizei len
GLuint num
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
unsigned int quint32
Definition qtypes.h:50
#define DEFINE_OBJECT_VTABLE(classname)
Symbol * symbol_toStringTag() const
Heap::String * newString(char16_t c)
ReturnedValue throwTypeError()
static ReturnedValue createIterResultObject(ExecutionEngine *engine, const Value &value, bool done)
void defineDefaultProperty(StringOrSymbol *name, const Value &value, PropertyAttributes attributes=Attr_Data|Attr_NotEnumerable)
bool set(StringOrSymbol *name, const Value &v, ThrowOnFailure shouldThrow)
void defineReadonlyConfigurableProperty(const QString &name, const Value &value)
ExecutionEngine * engine
static ReturnedValue method_next(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine)
static constexpr Value undefinedValue()
Definition qv4value_p.h:191
const T * as() const
Definition qv4value_p.h:132