18#include <wtf/MathExtras.h>
25#define BEGIN qDebug() << QByteArray(4*indent++, ' ').constData()
27#define DEBUG qDebug() << QByteArray(4*indent, ' ').constData()
29#define BEGIN if (1) ; else qDebug()
30#define END do {} while (0)
31#define DEBUG if (1) ; else qDebug()
88bool JsonParser::eatSpace()
104QChar JsonParser::nextToken()
109 switch (
token.unicode()) {
133 qDebug() <<
">>>>> parser begin";
140 if (!parseValue(
v)) {
142 qDebug() <<
">>>>> parser error";
146 error->offset = json - head;
147 error->error = lastError;
154 error->offset = json - head;
155 error->error = lastError;
162 return v->asReturnedValue();
177 BEGIN <<
"parseObject pos=" << json;
205 return o.asReturnedValue();
211bool JsonParser::parseMember(
Object *
o)
213 BEGIN <<
"parseMember";
217 if (!parseString(&
key))
225 if (!parseValue(
val))
234 o->insertMember(
s,
val);
247 BEGIN <<
"parseArray";
265 if (!parseValue(
val))
286 return array.asReturnedValue();
294bool JsonParser::parseValue(
Value *
val)
296 BEGIN <<
"parse Value" << *json;
298 switch ((json++)->unicode()) {
300 if (
end - json < 3) {
304 if (*json++ == u
'u' &&
308 DEBUG <<
"value: null";
315 if (
end - json < 3) {
319 if (*json++ == u
'r' &&
323 DEBUG <<
"value: true";
330 if (
end - json < 4) {
334 if (*json++ == u
'a' &&
339 DEBUG <<
"value: false";
347 if (!parseString(&
value))
349 DEBUG <<
"value: string";
356 if (
val->isUndefined())
358 DEBUG <<
"value: array";
363 *
val = parseObject();
364 if (
val->isUndefined())
366 DEBUG <<
"value: object";
375 if (!parseNumber(
val))
377 DEBUG <<
"value: number";
402bool JsonParser::parseNumber(
Value *
val)
404 BEGIN <<
"parseNumber" << *json;
410 if (json <
end && *json == u
'-')
414 if (json <
end && *json == u
'0') {
417 while (json < end && *json >= u
'0' && *json <= u
'9')
422 if (json <
end && *json == u
'.') {
425 while (json < end && *json >= u
'0' && *json <= u
'9')
430 if (json <
end && (*json == u
'e' || *json == u
'E')) {
433 if (json <
end && (*json == u
'-' || *json == u
'+'))
435 while (json < end && *json >= u
'0' && *json <= u
'9')
445 if (
ok &&
n < (1<<25) &&
n > -(1<<25)) {
493 if (
d >= u
'0' &&
d <= u
'9')
495 else if (
d >= u
'a' &&
d <= u
'f')
497 else if (
d >= u
'A' &&
d <= u
'F')
510 DEBUG <<
"scan escape";
511 uint escaped = (json++)->unicode();
533 for (
int i = 0;
i < 4; ++
i) {
547bool JsonParser::parseString(
QString *
string)
549 BEGIN <<
"parse string stringPos=" << json;
554 else if (*json == u
'\\') {
566 if (json->unicode() <= 0x1f) {
597 for (
int i = 0;
i < stack.
size(); ++
i)
598 if (stack.
at(
i)->d() ==
o->d())
628 bool foundProblem()
const {
return m_callDepthRecorder.ee->hasException; }
642 switch (
c.unicode()) {
665 if (
c.unicode() <= 0x1f) {
667 product += (
c.unicode() > 0xf ? u
'1' : u
'0') +
690 jsCallData.
args[0] = v4->newString(
key);
691 value = toJSON->call(jsCallData);
692 if (v4->hasException)
697 if (replacerFunction) {
699 jsCallData.
args[0] = v4->newString(
key);
702 if (stack.isEmpty()) {
710 value = replacerFunction->call(jsCallData);
711 if (v4->hasException)
715 o =
value->asReturnedValue();
720 value = so->d()->string;
727 if (
value->isBoolean())
729 if (
value->isString())
730 return quote(
value->stringValue()->toQString());
732 if (
value->isNumber()) {
733 double d =
value->toNumber();
738 return quote(
v->d()->data().toString());
741 o =
value->asReturnedValue();
744 if (
o->isArrayLike()) {
745 return JA(
o.getPointer());
782 if (!propertyListSize) {
798 for (
int i = 0;
i < propertyListSize; ++
i) {
803 v =
o->get(
s, &exists);
806 QString member = makeMember(
s->toQString(),
v);
812 if (partial.isEmpty()) {
814 }
else if (gap.isEmpty()) {
815 result = u
'{' + partial.join(u
',') + u
'}';
845 v =
a->get(
i, &exists);
857 if (partial.isEmpty()) {
859 }
else if (gap.isEmpty()) {
860 result = u
'[' + partial.join(u
',') + u
']';
863 result =
QLatin1String(
"[\n") + indent + partial.join(separator) + u
'\n' + stepback + u
']';
892 DEBUG <<
"parsing source = " << jtext;
897 DEBUG <<
"parse error" <<
error.errorString();
912 if (
o->isArrayObject()) {
916 for (
int i = 0;
i < arrayLen; ++
i) {
921 if (!
v->isString()) {
924 for (
int j = 0;
j <
i; ++
j) {
959 if (
value.isString())
961 else if (
value.isDouble())
963 else if (
value.isBool())
965 else if (
value.isArray())
967 else if (
value.isObject())
969 else if (
value.isNull())
977 if (
value.isNumber())
979 else if (
value.isBoolean())
981 else if (
value.isNull())
983 else if (
value.isUndefined())
992 return toJsonArray(
a, visitedObjects);
995 return toJsonObject(
o, visitedObjects);
1009 return o.asReturnedValue();
1018 Scope scope(
o->engine());
1033 name =
it.nextPropertyNameAsString(
val);
1052 a->arrayReserve(
size);
1054 for (
int i = 0;
i <
size;
i++)
1056 a->setArrayLengthUnchecked(
size);
1057 return a.asReturnedValue();
1066 Scope scope(
a->engine());
1083 result.append(toJsonValue(
v, visitedObjects));
bool foundProblem() const
CallDepthAndCycleChecker(Stringify *stringify, Object *o)
static constexpr bool requiresSurrogates(char32_t ucs4) noexcept
Returns true if the UCS-4-encoded character specified by ucs4 can be split into the high and low part...
static constexpr char16_t highSurrogate(char32_t ucs4) noexcept
Returns the high surrogate part of a UCS-4-encoded code point.
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
static constexpr char16_t lowSurrogate(char32_t ucs4) noexcept
Returns the low surrogate part of a UCS-4-encoded code point.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
bool remove(const T &value)
bool contains(const T &value) const
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
void reserve(qsizetype size)
Ensures the string has space for at least size characters.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
qsizetype size() const
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString & insert(qsizetype i, QChar c)
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
JsonParser(ExecutionEngine *engine, const QChar *json, int length)
ReturnedValue parse(QJsonParseError *error)
QSet< QString >::iterator it
\qmltype Particle \inqmlmodule QtQuick.Particles
DBusConnection const char DBusError * error
static QString stringify(const QString &data)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static bool scanEscapeSequence(const char *&json, const char *end, char32_t *ch)
static const int nestingLimit
static bool addHexDigit(char digit, char32_t *result)
constexpr const T & qMin(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static QString quote(const QString &str)
static const int nestingLimit
#define CHECK_EXCEPTION()
#define RETURN_UNDEFINED()
#define DEFINE_OBJECT_VTABLE(classname)
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
static constexpr ReturnedValue undefined()
static constexpr ReturnedValue null()
Heap::String * newString(const QString &s=QString())
Heap::Object * newObject()
int safeForAllocLength(qint64 len64)
Symbol * symbol_toStringTag() const
String * id_empty() const
Heap::ArrayObject * newArrayObject(int count=0)
ReturnedValue throwSyntaxError(const QString &message)
ReturnedValue asReturnedValue() const
static ReturnedValue fromJsonValue(ExecutionEngine *engine, const QJsonValue &value)
static ReturnedValue fromJsonObject(ExecutionEngine *engine, const QJsonObject &object)
static ReturnedValue fromJsonArray(ExecutionEngine *engine, const QJsonArray &array)
static ReturnedValue method_parse(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static QJsonObject toJsonObject(const QV4::Object *o)
static QJsonArray toJsonArray(const QV4::ArrayObject *a)
static ReturnedValue method_stringify(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static QJsonValue toJsonValue(const QV4::Value &value)
Heap::InternalClass * internalClass() const
ExecutionEngine * engine() const
bool isArrayIndex() const
uint asArrayIndex() const
Value * alloc(qint64 nValues) const =delete
bool hasException() const
static constexpr Value fromInt32(int i)
QML_NEARLY_ALWAYS_INLINE String * stringValue() const
static constexpr Value fromBoolean(bool b)
static constexpr Value undefinedValue()
static Value fromDouble(double d)
static Value fromHeapObject(HeapBasePtr m)
QString toQString() const
static constexpr Value nullValue()
FunctionObject * replacerFunction
QString makeMember(const QString &key, const Value &v)
QV4::String * propertyList
bool stackContains(Object *o)
QString Str(const QString &key, const Value &v)
Stringify(ExecutionEngine *e)