Merge branch 'master' of https://git.shs.tools/SHS/pip
This commit is contained in:
@@ -88,7 +88,6 @@
|
||||
//!
|
||||
|
||||
|
||||
|
||||
PIJSON PIJSON::newObject() {
|
||||
PIJSON ret;
|
||||
ret.c_type = Object;
|
||||
@@ -111,16 +110,20 @@ PIJSON PIJSON::newString(const PIString & v) {
|
||||
|
||||
|
||||
const PIVector<PIJSON> & PIJSON::array() const {
|
||||
if (!isArray())
|
||||
if (!isArray()) {
|
||||
return nullEntry().c_array;
|
||||
} else {
|
||||
return c_array;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const PIMap<PIString, PIJSON> & PIJSON::object() const {
|
||||
if (!isObject())
|
||||
if (!isObject()) {
|
||||
return nullEntry().c_object;
|
||||
return c_object;
|
||||
} else {
|
||||
return c_object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,10 +168,8 @@ void PIJSON::clear() {
|
||||
|
||||
|
||||
int PIJSON::size() const {
|
||||
if (isArray())
|
||||
return c_array.size_s();
|
||||
if (isObject())
|
||||
return c_object.size_s();
|
||||
if (isArray()) return c_array.size_s();
|
||||
if (isObject()) return c_object.size_s();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -186,16 +187,16 @@ void PIJSON::resize(int new_size) {
|
||||
|
||||
|
||||
const PIJSON & PIJSON::operator[](int index) const {
|
||||
if (!isArray())
|
||||
return nullEntry();
|
||||
if (!isArray()) return nullEntry();
|
||||
return c_array[index];
|
||||
}
|
||||
|
||||
|
||||
PIJSON & PIJSON::operator[](int index) {
|
||||
c_type = Array;
|
||||
if (index >= c_array.size_s())
|
||||
if (index >= c_array.size_s()) {
|
||||
c_array.resize(index + 1, newString());
|
||||
}
|
||||
PIJSON & ret(c_array[index]);
|
||||
return ret;
|
||||
}
|
||||
@@ -211,10 +212,8 @@ PIJSON & PIJSON::operator=(const PIJSON & v) {
|
||||
|
||||
|
||||
PIJSON PIJSON::operator[](const PIString & key) const {
|
||||
if (!isObject())
|
||||
return nullEntry();
|
||||
if (!c_object.contains(key))
|
||||
return nullEntry();
|
||||
if (!isObject()) return nullEntry();
|
||||
if (!c_object.contains(key)) return nullEntry();
|
||||
return c_object.value(key);
|
||||
}
|
||||
|
||||
@@ -263,11 +262,11 @@ PIJSON PIJSON::parseValue(PIString & s) {
|
||||
//piCout << "\n\n\n parseValue" << s;
|
||||
s.trim();
|
||||
if (s.isEmpty()) return ret;
|
||||
if (s[0] == '{')
|
||||
if (s[0] == '{') {
|
||||
ret = parseObject(s.takeRange('{', '}'));
|
||||
else if (s[0] == '[')
|
||||
} else if (s[0] == '[') {
|
||||
ret = parseArray(s.takeRange('[', ']'));
|
||||
else {
|
||||
} else {
|
||||
s.trim();
|
||||
if (s.startsWith('"')) {
|
||||
ret.c_type = PIJSON::String;
|
||||
@@ -417,11 +416,12 @@ void PIJSON::print(PIString & s, const PIJSON & v, PIString tab, bool spaces, bo
|
||||
s += "{";
|
||||
if (spaces) s += '\n';
|
||||
{
|
||||
PIString ntab = tab + " ";
|
||||
auto it = v.c_object.makeIterator();
|
||||
int cnt = 0;
|
||||
while (it.next())
|
||||
print(s, it.value(), ntab, spaces, transform, ++cnt < v.c_object.size_s());
|
||||
PIString ntab = tab + " ";
|
||||
auto it = v.c_object.makeIterator();
|
||||
int cnt = 0;
|
||||
while (it.next()) {
|
||||
print(s, it.value(), ntab, spaces, transform, ++cnt < v.c_object.size_s());
|
||||
}
|
||||
}
|
||||
if (spaces) s += tab;
|
||||
s += "}";
|
||||
@@ -430,9 +430,10 @@ void PIJSON::print(PIString & s, const PIJSON & v, PIString tab, bool spaces, bo
|
||||
s += "[";
|
||||
if (spaces) s += '\n';
|
||||
{
|
||||
PIString ntab = tab + " ";
|
||||
for (int i = 0; i < v.c_array.size_s(); ++i)
|
||||
print(s, v.c_array[i], ntab, spaces, transform, i < v.c_array.size_s() - 1);
|
||||
PIString ntab = tab + " ";
|
||||
for (int i = 0; i < v.c_array.size_s(); ++i) {
|
||||
print(s, v.c_array[i], ntab, spaces, transform, i < v.c_array.size_s() - 1);
|
||||
}
|
||||
}
|
||||
if (spaces) s += tab;
|
||||
s += "]";
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
|
||||
//! \~english Returns text representation of JSON tree.
|
||||
//! \~russian Возвращает текстовое представление дерева JSON.
|
||||
PIString toJSON(PrintType print_type = Tree) const;
|
||||
PIString toJSON(PrintType print_type = Compact) const;
|
||||
|
||||
//! \~english Parse text representation of JSON "str" and returns it root element.
|
||||
//! \~russian Разбирает текстовое представление JSON "str" и возвращает его корневой элемент.
|
||||
@@ -181,8 +181,8 @@ private:
|
||||
static PIJSON parseValue(PIString & s);
|
||||
static PIJSON parseObject(PIString s);
|
||||
static PIJSON parseArray(PIString s);
|
||||
static PIString stringMask(const PIString & s);;
|
||||
static PIString stringUnmask(const PIString & s);;
|
||||
static PIString stringMask(const PIString & s);
|
||||
static PIString stringUnmask(const PIString & s);
|
||||
static void print(PIString & s, const PIJSON & v, PIString tab, bool spaces, bool transform = false, bool comma = false);
|
||||
|
||||
PIString c_name;
|
||||
|
||||
Reference in New Issue
Block a user