mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-14 17:47:21 +01:00
Updated qt-json library.
This commit is contained in:
parent
574d25414e
commit
e9d39454dc
@ -41,7 +41,7 @@ namespace QtJson {
|
||||
|
||||
template<typename T>
|
||||
QByteArray serializeMap(const T &map, bool &success) {
|
||||
QByteArray str = "{ ";
|
||||
QByteArray str = "{";
|
||||
QList<QByteArray> pairs;
|
||||
for (typename T::const_iterator it = map.begin(), itend = map.end(); it != itend; ++it) {
|
||||
QByteArray serializedValue = serialize(it.value());
|
||||
@ -49,11 +49,11 @@ namespace QtJson {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
pairs << sanitizeString(it.key()).toUtf8() + " : " + serializedValue;
|
||||
pairs << sanitizeString(it.key()).toUtf8() + ":" + serializedValue;
|
||||
}
|
||||
|
||||
str += join(pairs, ", ");
|
||||
str += " }";
|
||||
str += join(pairs, ",");
|
||||
str += "}";
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ namespace QtJson {
|
||||
values << serializedValue;
|
||||
}
|
||||
|
||||
str = "[ " + join( values, ", " ) + " ]";
|
||||
str = "[" + join( values, "," ) + "]";
|
||||
} else if (data.type() == QVariant::Hash) { // variant is a hash?
|
||||
str = serializeMap<>(data.toHash(), success);
|
||||
} else if (data.type() == QVariant::Map) { // variant is a map?
|
||||
|
@ -129,6 +129,50 @@ namespace QtJson {
|
||||
*/
|
||||
QString getDateTimeFormat();
|
||||
QString getDateFormat();
|
||||
|
||||
/**
|
||||
* QVariant based Json object
|
||||
*/
|
||||
class Object : public QVariant {
|
||||
template<typename T>
|
||||
Object& insertKey(Object* ptr, const QString& key) {
|
||||
T* p = (T*)ptr->data();
|
||||
if (!p->contains(key)) p->insert(key, QVariant());
|
||||
return *reinterpret_cast<Object*>(&p->operator[](key));
|
||||
}
|
||||
template<typename T>
|
||||
void removeKey(Object *ptr, const QString& key) {
|
||||
T* p = (T*)ptr->data();
|
||||
p->remove(key);
|
||||
}
|
||||
public:
|
||||
Object() : QVariant() {}
|
||||
Object(const Object& ref) : QVariant(ref) {}
|
||||
|
||||
Object& operator=(const QVariant& rhs) {
|
||||
setValue(rhs);
|
||||
return *this;
|
||||
}
|
||||
Object& operator[](const QString& key) {
|
||||
if (type() == QVariant::Map)
|
||||
return insertKey<QVariantMap>(this, key);
|
||||
else if (type() == QVariant::Hash)
|
||||
return insertKey<QVariantHash>(this, key);
|
||||
|
||||
setValue(QVariantMap());
|
||||
|
||||
return insertKey<QVariantMap>(this, key);
|
||||
}
|
||||
const Object& operator[](const QString& key) const {
|
||||
return const_cast<Object*>(this)->operator[](key);
|
||||
}
|
||||
void remove(const QString& key) {
|
||||
if (type() == QVariant::Map)
|
||||
removeKey<QVariantMap>(this, key);
|
||||
else if (type() == QVariant::Hash)
|
||||
removeKey<QVariantHash>(this, key);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //JSON_H
|
||||
|
Loading…
Reference in New Issue
Block a user