forked from qt-creator/qt-creator
Remove stale shared/json directory
Symbian leftovers Change-Id: I4479113b6f80eb4a667054d72da1b185c315f61d Reviewed-by: Kai Koehne <kai.koehne@nokia.com> Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
5c4fddc6a5
commit
fb6b15f957
@@ -272,15 +272,6 @@ QtcPlugin {
|
||||
]
|
||||
}
|
||||
|
||||
Group {
|
||||
prefix: "../../shared/json/"
|
||||
files: [
|
||||
"json_global.h",
|
||||
"json.cpp",
|
||||
"json.h"
|
||||
]
|
||||
}
|
||||
|
||||
Group {
|
||||
condition: qbs.targetOS == "windows"
|
||||
files: [
|
||||
|
@@ -1,549 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the GNU Lesser General
|
||||
** Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "json.h"
|
||||
|
||||
#ifdef TODO_USE_CREATOR
|
||||
#include <utils/qtcassert.h>
|
||||
#endif // TODO_USE_CREATOR
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef DEBUG_JASON
|
||||
#define JDEBUG(s) qDebug() << s
|
||||
#else
|
||||
#define JDEBUG(s)
|
||||
#endif
|
||||
|
||||
using namespace Json;
|
||||
|
||||
static void skipSpaces(const char *&from, const char *to)
|
||||
{
|
||||
while (from != to && isspace(*from))
|
||||
++from;
|
||||
}
|
||||
|
||||
QTextStream &operator<<(QTextStream &os, const JsonValue &mi)
|
||||
{
|
||||
return os << mi.toString();
|
||||
}
|
||||
|
||||
void JsonValue::parsePair(const char *&from, const char *to)
|
||||
{
|
||||
skipSpaces(from, to);
|
||||
JDEBUG("parsePair: " << QByteArray(from, to - from));
|
||||
m_name = parseCString(from, to);
|
||||
skipSpaces(from, to);
|
||||
while (from < to && *from != ':') {
|
||||
JDEBUG("not a colon" << *from);
|
||||
++from;
|
||||
}
|
||||
++from;
|
||||
parseValue(from, to);
|
||||
skipSpaces(from, to);
|
||||
}
|
||||
|
||||
QByteArray JsonValue::parseNumber(const char *&from, const char *to)
|
||||
{
|
||||
QByteArray result;
|
||||
if (from < to && *from == '-') // Leading '-'.
|
||||
result.append(*from++);
|
||||
while (from < to && *from >= '0' && *from <= '9')
|
||||
result.append(*from++);
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray JsonValue::parseCString(const char *&from, const char *to)
|
||||
{
|
||||
QByteArray result;
|
||||
const char * const fromSaved = from;
|
||||
JDEBUG("parseCString: " << QByteArray(from, to - from));
|
||||
if (*from != '"') {
|
||||
qDebug() << "JSON Parse Error, double quote expected";
|
||||
++from; // So we don't hang
|
||||
return QByteArray();
|
||||
}
|
||||
const char *ptr = from;
|
||||
++ptr;
|
||||
while (ptr < to) {
|
||||
if (*ptr == '"') {
|
||||
++ptr;
|
||||
result = QByteArray(from + 1, ptr - from - 2);
|
||||
break;
|
||||
}
|
||||
if (*ptr == '\\') {
|
||||
++ptr;
|
||||
if (ptr == to) {
|
||||
qWarning("JSON Parse Error, unterminated backslash escape in '%s'",
|
||||
QByteArray(fromSaved, to - fromSaved).constData());
|
||||
from = ptr; // So we don't hang
|
||||
return QByteArray();
|
||||
}
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
from = ptr;
|
||||
|
||||
int idx = result.indexOf('\\');
|
||||
if (idx >= 0) {
|
||||
char *dst = result.data() + idx;
|
||||
const char *src = dst + 1, *end = result.data() + result.length();
|
||||
do {
|
||||
char c = *src++;
|
||||
switch (c) {
|
||||
case 'a': *dst++ = '\a'; break;
|
||||
case 'b': *dst++ = '\b'; break;
|
||||
case 'f': *dst++ = '\f'; break;
|
||||
case 'n': *dst++ = '\n'; break;
|
||||
case 'r': *dst++ = '\r'; break;
|
||||
case 't': *dst++ = '\t'; break;
|
||||
case 'v': *dst++ = '\v'; break;
|
||||
case '"': *dst++ = '"'; break;
|
||||
case '\\': *dst++ = '\\'; break;
|
||||
case 'u': { // 4 digit hex escape as in '\u000a'
|
||||
if (end - src < 4) {
|
||||
qWarning("JSON Parse Error, too few hex digits in \\u-escape in '%s' obtained from '%s'",
|
||||
result.constData(), QByteArray(fromSaved, to - fromSaved).constData());
|
||||
return QByteArray();
|
||||
}
|
||||
bool ok;
|
||||
const uchar prod = QByteArray(src, 4).toUInt(&ok, 16);
|
||||
if (!ok) {
|
||||
qWarning("JSON Parse Error, invalid hex digits in \\u-escape in '%s' obtained from '%s'",
|
||||
result.constData(), QByteArray(fromSaved, to - fromSaved).constData());
|
||||
return QByteArray();
|
||||
}
|
||||
*dst++ = prod;
|
||||
src += 4;
|
||||
}
|
||||
break;
|
||||
default: { // Up to 3 decimal digits: Not sure if this is supported in JSON?
|
||||
int chars = 0;
|
||||
uchar prod = 0;
|
||||
forever {
|
||||
if (c < '0' || c > '7') {
|
||||
--src;
|
||||
break;
|
||||
}
|
||||
prod = prod * 8 + c - '0';
|
||||
if (++chars == 3 || src == end)
|
||||
break;
|
||||
c = *src++;
|
||||
}
|
||||
if (!chars) {
|
||||
qWarning("JSON Parse Error, unrecognized backslash escape in string '%s' obtained from '%s'",
|
||||
result.constData(), QByteArray(fromSaved, to - fromSaved).constData());
|
||||
return QByteArray();
|
||||
}
|
||||
*dst++ = prod;
|
||||
}
|
||||
}
|
||||
while (src != end) {
|
||||
char c = *src++;
|
||||
if (c == '\\')
|
||||
break;
|
||||
*dst++ = c;
|
||||
}
|
||||
} while (src != end);
|
||||
*dst = 0;
|
||||
result.truncate(dst - result.data());
|
||||
}
|
||||
|
||||
JDEBUG("parseCString, got " << result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JsonValue::parseValue(const char *&from, const char *to)
|
||||
{
|
||||
JDEBUG("parseValue: " << QByteArray(from, to - from));
|
||||
switch (*from) {
|
||||
case '{':
|
||||
parseObject(from, to);
|
||||
break;
|
||||
case 't':
|
||||
if (to - from >= 4 && qstrncmp(from, "true", 4) == 0) {
|
||||
m_data = QByteArray(from, 4);
|
||||
from += m_data.size();
|
||||
m_type = Boolean;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
if (to - from >= 5 && qstrncmp(from, "false", 5) == 0) {
|
||||
m_data = QByteArray(from, 5);
|
||||
from += m_data.size();
|
||||
m_type = Boolean;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (to - from >= 4 && qstrncmp(from, "null", 4) == 0) {
|
||||
m_data = QByteArray(from, 4);
|
||||
from += m_data.size();
|
||||
m_type = NullObject;
|
||||
}
|
||||
break;
|
||||
case '[':
|
||||
parseArray(from, to);
|
||||
break;
|
||||
case '"':
|
||||
m_type = String;
|
||||
m_data = parseCString(from, to);
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
case '-':
|
||||
m_type = Number;
|
||||
m_data = parseNumber(from, to);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void JsonValue::parseObject(const char *&from, const char *to)
|
||||
{
|
||||
JDEBUG("parseObject: " << QByteArray(from, to - from));
|
||||
#ifdef TODO_USE_CREATOR
|
||||
QTC_CHECK(*from == '{');
|
||||
#endif
|
||||
++from;
|
||||
m_type = Object;
|
||||
while (from < to) {
|
||||
if (*from == '}') {
|
||||
++from;
|
||||
break;
|
||||
}
|
||||
JsonValue child;
|
||||
child.parsePair(from, to);
|
||||
if (!child.isValid())
|
||||
return;
|
||||
m_children += child;
|
||||
if (*from == ',')
|
||||
++from;
|
||||
}
|
||||
}
|
||||
|
||||
void JsonValue::parseArray(const char *&from, const char *to)
|
||||
{
|
||||
JDEBUG("parseArray: " << QByteArray(from, to - from));
|
||||
#ifdef TODO_USE_CREATOR
|
||||
QTC_CHECK(*from == '[');
|
||||
#endif
|
||||
++from;
|
||||
m_type = Array;
|
||||
while (from < to) {
|
||||
if (*from == ']') {
|
||||
++from;
|
||||
break;
|
||||
}
|
||||
JsonValue child;
|
||||
child.parseValue(from, to);
|
||||
if (child.isValid())
|
||||
m_children += child;
|
||||
if (*from == ',')
|
||||
++from;
|
||||
}
|
||||
}
|
||||
|
||||
void JsonValue::setStreamOutput(const QByteArray &name, const QByteArray &content)
|
||||
{
|
||||
if (content.isEmpty())
|
||||
return;
|
||||
JsonValue child;
|
||||
child.m_type = String;
|
||||
child.m_name = name;
|
||||
child.m_data = content;
|
||||
m_children += child;
|
||||
if (m_type == Invalid)
|
||||
m_type = Object;
|
||||
}
|
||||
|
||||
static QByteArray ind(int indent)
|
||||
{
|
||||
return QByteArray(2 * indent, ' ');
|
||||
}
|
||||
|
||||
void JsonValue::dumpChildren(QByteArray * str, bool multiline, int indent) const
|
||||
{
|
||||
for (int i = 0; i < m_children.size(); ++i) {
|
||||
if (i != 0) {
|
||||
*str += ',';
|
||||
if (multiline)
|
||||
*str += '\n';
|
||||
}
|
||||
if (multiline)
|
||||
*str += ind(indent);
|
||||
*str += m_children.at(i).toString(multiline, indent);
|
||||
}
|
||||
}
|
||||
|
||||
class MyString : public QString {
|
||||
public:
|
||||
ushort at(int i) const { return constData()[i].unicode(); }
|
||||
};
|
||||
|
||||
template<class ST, typename CT>
|
||||
inline ST escapeCStringTpl(const ST &ba)
|
||||
{
|
||||
ST ret;
|
||||
ret.reserve(ba.length() * 2);
|
||||
for (int i = 0; i < ba.length(); ++i) {
|
||||
CT c = ba.at(i);
|
||||
switch (c) {
|
||||
case '\\': ret += "\\\\"; break;
|
||||
case '\a': ret += "\\a"; break;
|
||||
case '\b': ret += "\\b"; break;
|
||||
case '\f': ret += "\\f"; break;
|
||||
case '\n': ret += "\\n"; break;
|
||||
case '\r': ret += "\\r"; break;
|
||||
case '\t': ret += "\\t"; break;
|
||||
case '\v': ret += "\\v"; break;
|
||||
case '"': ret += "\\\""; break;
|
||||
default:
|
||||
if (c < 32 || c == 127) {
|
||||
ret += '\\';
|
||||
ret += '0' + (c >> 6);
|
||||
ret += '0' + ((c >> 3) & 7);
|
||||
ret += '0' + (c & 7);
|
||||
} else {
|
||||
ret += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString JsonValue::escapeCString(const QString &ba)
|
||||
{
|
||||
return escapeCStringTpl<MyString, ushort>(static_cast<const MyString &>(ba));
|
||||
}
|
||||
|
||||
QByteArray JsonValue::escapeCString(const QByteArray &ba)
|
||||
{
|
||||
return escapeCStringTpl<QByteArray, uchar>(ba);
|
||||
}
|
||||
|
||||
QByteArray JsonValue::toString(bool multiline, int indent) const
|
||||
{
|
||||
QByteArray result;
|
||||
switch (m_type) {
|
||||
case Invalid:
|
||||
if (multiline)
|
||||
result += ind(indent) + "Invalid\n";
|
||||
else
|
||||
result += "Invalid";
|
||||
break;
|
||||
case String:
|
||||
if (!m_name.isEmpty())
|
||||
result += m_name + '=';
|
||||
result += '"' + escapeCString(m_data) + '"';
|
||||
break;
|
||||
case Number:
|
||||
if (!m_name.isEmpty())
|
||||
result += '"' + m_name + "\":";
|
||||
result += m_data;
|
||||
break;
|
||||
case Boolean:
|
||||
case NullObject:
|
||||
if (!m_name.isEmpty())
|
||||
result += '"' + m_name + "\":";
|
||||
result += m_data;
|
||||
break;
|
||||
case Object:
|
||||
if (!m_name.isEmpty())
|
||||
result += m_name + '=';
|
||||
if (multiline) {
|
||||
result += "{\n";
|
||||
dumpChildren(&result, multiline, indent + 1);
|
||||
result += '\n' + ind(indent) + '}';
|
||||
} else {
|
||||
result += '{';
|
||||
dumpChildren(&result, multiline, indent + 1);
|
||||
result += '}';
|
||||
}
|
||||
break;
|
||||
case Array:
|
||||
if (!m_name.isEmpty())
|
||||
result += m_name + '=';
|
||||
if (multiline) {
|
||||
result += "[\n";
|
||||
dumpChildren(&result, multiline, indent + 1);
|
||||
result += '\n' + ind(indent) + ']';
|
||||
} else {
|
||||
result += '[';
|
||||
dumpChildren(&result, multiline, indent + 1);
|
||||
result += ']';
|
||||
}
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
QVariant JsonValue::toVariant() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case String:
|
||||
return QString(m_data);
|
||||
case Number: {
|
||||
bool ok;
|
||||
qint64 val = QString(m_data).toLongLong(&ok);
|
||||
if (ok)
|
||||
return val;
|
||||
return QVariant();
|
||||
}
|
||||
case Object: {
|
||||
QHash<QString, QVariant> hash;
|
||||
for (int i = 0; i < m_children.size(); ++i) {
|
||||
QString name(m_children[i].name());
|
||||
QVariant val = m_children[i].toVariant();
|
||||
hash.insert(name, val);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
case Array: {
|
||||
QList<QVariant> list;
|
||||
for (int i = 0; i < m_children.size(); ++i) {
|
||||
list.append(m_children[i].toVariant());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
case Boolean:
|
||||
return data() == QByteArray("true");
|
||||
case Invalid:
|
||||
case NullObject:
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JsonValue::fromString(const QByteArray &ba)
|
||||
{
|
||||
const char *from = ba.constBegin();
|
||||
const char *to = ba.constEnd();
|
||||
parseValue(from, to);
|
||||
}
|
||||
|
||||
JsonValue JsonValue::findChild(const char *name) const
|
||||
{
|
||||
for (int i = 0; i < m_children.size(); ++i)
|
||||
if (m_children.at(i).m_name == name)
|
||||
return m_children.at(i);
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
void JsonInputStream::appendCString(const char *s)
|
||||
{
|
||||
m_target.append('"');
|
||||
for (const char *p = s; *p; p++) {
|
||||
if (*p == '"' || *p == '\\')
|
||||
m_target.append('\\');
|
||||
m_target.append(*p);
|
||||
}
|
||||
m_target.append('"');
|
||||
}
|
||||
|
||||
void JsonInputStream::appendString(const QString &in)
|
||||
{
|
||||
if (in.isEmpty()) {
|
||||
m_target.append("\"\"");
|
||||
return;
|
||||
}
|
||||
|
||||
const QChar doubleQuote('"');
|
||||
const QChar backSlash('\\');
|
||||
QString rc;
|
||||
const int inSize = in.size();
|
||||
rc.reserve(in.size() + 5);
|
||||
rc.append(doubleQuote);
|
||||
for (int i = 0; i < inSize; i++) {
|
||||
const QChar c = in.at(i);
|
||||
if (c == doubleQuote || c == backSlash)
|
||||
rc.append(backSlash);
|
||||
rc.append(c);
|
||||
}
|
||||
rc.append(doubleQuote);
|
||||
m_target.append(rc.toUtf8());
|
||||
return;
|
||||
}
|
||||
|
||||
JsonInputStream &JsonInputStream::operator<<(const QStringList &in)
|
||||
{
|
||||
m_target.append('[');
|
||||
const int count = in.size();
|
||||
for (int i = 0 ; i < count; i++) {
|
||||
if (i)
|
||||
m_target.append(',');
|
||||
appendString(in.at(i));
|
||||
}
|
||||
m_target.append(']');
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonInputStream &JsonInputStream::operator<<(const QVector<QByteArray> &ba)
|
||||
{
|
||||
m_target.append('[');
|
||||
const int count = ba.size();
|
||||
for (int i = 0 ; i < count; i++) {
|
||||
if (i)
|
||||
m_target.append(',');
|
||||
appendCString(ba.at(i).constData());
|
||||
}
|
||||
m_target.append(']');
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonInputStream &JsonInputStream::operator<<(const QList<int> &in)
|
||||
{
|
||||
m_target.append('[');
|
||||
const int count = in.size();
|
||||
for (int i = 0 ; i < count; i++) {
|
||||
if (i)
|
||||
m_target.append(',');
|
||||
m_target.append(QByteArray::number(in.at(i)));
|
||||
}
|
||||
m_target.append(']');
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonInputStream &JsonInputStream::operator<<(bool b)
|
||||
{
|
||||
m_target.append(b ? "true" : "false");
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@@ -1,143 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the GNU Lesser General
|
||||
** Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef JSON_H
|
||||
#define JSON_H
|
||||
|
||||
#include "json_global.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
|
||||
namespace Json {
|
||||
|
||||
class JSON_EXPORT JsonValue
|
||||
{
|
||||
public:
|
||||
JsonValue() : m_type(Invalid) {}
|
||||
explicit JsonValue(const QByteArray &str) { fromString(str); }
|
||||
|
||||
QByteArray m_name;
|
||||
QByteArray m_data;
|
||||
QList<JsonValue> m_children;
|
||||
|
||||
enum Type {
|
||||
Invalid,
|
||||
String,
|
||||
Number,
|
||||
Boolean,
|
||||
Object,
|
||||
NullObject,
|
||||
Array
|
||||
};
|
||||
|
||||
Type m_type;
|
||||
|
||||
inline Type type() const { return m_type; }
|
||||
inline QByteArray name() const { return m_name; }
|
||||
inline bool hasName(const char *name) const { return m_name == name; }
|
||||
|
||||
inline bool isValid() const { return m_type != Invalid; }
|
||||
inline bool isNumber() const { return m_type == Number; }
|
||||
inline bool isString() const { return m_type == String; }
|
||||
inline bool isObject() const { return m_type == Object; }
|
||||
inline bool isArray() const { return m_type == Array; }
|
||||
|
||||
|
||||
inline QByteArray data() const { return m_data; }
|
||||
inline const QList<JsonValue> &children() const { return m_children; }
|
||||
inline int childCount() const { return m_children.size(); }
|
||||
|
||||
const JsonValue &childAt(int index) const { return m_children[index]; }
|
||||
JsonValue &childAt(int index) { return m_children[index]; }
|
||||
JsonValue findChild(const char *name) const;
|
||||
|
||||
QByteArray toString(bool multiline = false, int indent = 0) const;
|
||||
void fromString(const QByteArray &str);
|
||||
void setStreamOutput(const QByteArray &name, const QByteArray &content);
|
||||
|
||||
QVariant toVariant() const;
|
||||
|
||||
private:
|
||||
static QByteArray parseCString(const char *&from, const char *to);
|
||||
static QByteArray parseNumber(const char *&from, const char *to);
|
||||
static QByteArray escapeCString(const QByteArray &ba);
|
||||
static QString escapeCString(const QString &ba);
|
||||
void parsePair(const char *&from, const char *to);
|
||||
void parseValue(const char *&from, const char *to);
|
||||
void parseObject(const char *&from, const char *to);
|
||||
void parseArray(const char *&from, const char *to);
|
||||
|
||||
void dumpChildren(QByteArray *str, bool multiline, int indent) const;
|
||||
};
|
||||
|
||||
/* Thin wrapper around QByteArray for formatting JSON input. Use as in:
|
||||
* JsonInputStream(byteArray) << '{' << "bla" << ':' << "blup" << '}';
|
||||
* Note that strings get double quotes and JSON-escaping, characters should be
|
||||
* used for the array/hash delimiters.
|
||||
* */
|
||||
class JSON_EXPORT JsonInputStream {
|
||||
public:
|
||||
explicit JsonInputStream(QByteArray &a) : m_target(a) {}
|
||||
|
||||
JsonInputStream &operator<<(char c) { m_target.append(c); return *this; }
|
||||
JsonInputStream &operator<<(const char *c) { appendCString(c); return *this; }
|
||||
JsonInputStream &operator<<(const QByteArray &a) { appendCString(a.constData()); return *this; }
|
||||
JsonInputStream &operator<<(const QString &c) { appendString(c); return *this; }
|
||||
|
||||
// Format as array
|
||||
JsonInputStream &operator<<(const QStringList &c);
|
||||
|
||||
// Format as array
|
||||
JsonInputStream &operator<<(const QVector<QByteArray> &ba);
|
||||
|
||||
//Format as array
|
||||
JsonInputStream &operator<<(const QList<int> &in);
|
||||
|
||||
JsonInputStream &operator<<(bool b);
|
||||
|
||||
JsonInputStream &operator<<(int i)
|
||||
{ m_target.append(QByteArray::number(i)); return *this; }
|
||||
JsonInputStream &operator<<(unsigned i)
|
||||
{ m_target.append(QByteArray::number(i)); return *this; }
|
||||
JsonInputStream &operator<<(quint64 i)
|
||||
{ m_target.append(QByteArray::number(i)); return *this; }
|
||||
|
||||
private:
|
||||
void appendString(const QString &);
|
||||
void appendCString(const char *c);
|
||||
|
||||
QByteArray &m_target;
|
||||
};
|
||||
|
||||
} //namespace Json
|
||||
|
||||
#endif // JSON_H
|
@@ -1,7 +0,0 @@
|
||||
INCLUDEPATH *= $$PWD
|
||||
|
||||
# Input
|
||||
HEADERS += $$PWD/json_global.h \
|
||||
$$PWD/json.h
|
||||
|
||||
SOURCES += $$PWD/json.cpp
|
@@ -1,44 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the GNU Lesser General
|
||||
** Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef JSON_GLOBAL_H
|
||||
#define JSON_GLOBAL_H
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
#if defined(JSON_BUILD_LIB)
|
||||
# define JSON_EXPORT Q_DECL_EXPORT
|
||||
#elif defined(JSON_BUILD_STATIC_LIB) || defined(JSON_INCLUDE_PRI)
|
||||
# define JSON_EXPORT
|
||||
#else
|
||||
# define JSON_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // JSON_GLOBAL_H
|
@@ -1,11 +1,9 @@
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += core-private
|
||||
include(../qttest.pri)
|
||||
include($$IDE_SOURCE_TREE/src/shared/json/json.pri)
|
||||
include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri)
|
||||
DEFINES += JSON_INCLUDE_PRI
|
||||
|
||||
DEBUGGERDIR = $$IDE_SOURCE_TREE/src/plugins/debugger
|
||||
UTILSDIR = $$IDE_SOURCE_TREE/src/libs
|
||||
UTILSDIR = $$IDE_SOURCE_TREE/src/libs/utils
|
||||
MACROSDIR = $$IDE_SOURCE_TREE/share/qtcreator/dumper
|
||||
|
||||
SOURCES += \
|
||||
|
@@ -164,7 +164,7 @@ public:
|
||||
|
||||
void testJson(const char* input)
|
||||
{
|
||||
QCOMPARE('\n' + QString::fromLatin1(Json::JsonValue(input).toString(false)),
|
||||
QCOMPARE('\n' + Utils::JsonStringValue(QLatin1String(input)).value(),
|
||||
'\n' + QString(input));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user