code format
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
JSON class
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
JSON class
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "pijson.h"
|
||||
|
||||
@@ -275,7 +275,7 @@ void PIJSON::setValue(const PIVariant & v) {
|
||||
|
||||
|
||||
void PIJSON::clear() {
|
||||
c_type = Invalid;
|
||||
c_type = Invalid;
|
||||
c_value = PIVariant();
|
||||
c_name.clear();
|
||||
c_object.clear();
|
||||
@@ -326,10 +326,10 @@ PIJSON & PIJSON::operator<<(const PIJSON & element) {
|
||||
|
||||
|
||||
PIJSON & PIJSON::operator=(const PIJSON & v) {
|
||||
c_type = v.c_type;
|
||||
c_value = v.c_value;
|
||||
c_type = v.c_type;
|
||||
c_value = v.c_value;
|
||||
c_object = v.c_object;
|
||||
c_array = v.c_array;
|
||||
c_array = v.c_array;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ PIJSON & PIJSON::nullEntry() {
|
||||
|
||||
|
||||
PIString PIJSON::parseName(PIString & s) {
|
||||
//piCout << "\n\n\n parseName" << s;
|
||||
// piCout << "\n\n\n parseName" << s;
|
||||
PIString ret;
|
||||
ret = s.takeRange('"', '"');
|
||||
s.trim();
|
||||
@@ -382,7 +382,7 @@ PIString PIJSON::parseName(PIString & s) {
|
||||
|
||||
PIJSON PIJSON::parseValue(PIString & s) {
|
||||
PIJSON ret;
|
||||
//piCout << "\n\n\n parseValue" << s;
|
||||
// piCout << "\n\n\n parseValue" << s;
|
||||
s.trim();
|
||||
if (s.isEmpty()) return ret;
|
||||
if (s[0] == '{') {
|
||||
@@ -392,7 +392,7 @@ PIJSON PIJSON::parseValue(PIString & s) {
|
||||
} else {
|
||||
s.trim();
|
||||
if (s.startsWith('"')) {
|
||||
ret.c_type = PIJSON::String;
|
||||
ret.c_type = PIJSON::String;
|
||||
ret.c_value = PIJSON::stringUnmask(s.takeRange('"', '"'));
|
||||
} else {
|
||||
PIString value;
|
||||
@@ -403,17 +403,17 @@ PIJSON PIJSON::parseValue(PIString & s) {
|
||||
value = s;
|
||||
s.clear();
|
||||
}
|
||||
//piCout << "\n\n\n parseValue value = \"" << value << "\"";
|
||||
// piCout << "\n\n\n parseValue value = \"" << value << "\"";
|
||||
if (value == "null") {
|
||||
ret.c_type = PIJSON::Null;
|
||||
} else if (value == "true") {
|
||||
ret.c_type = PIJSON::Boolean;
|
||||
ret.c_type = PIJSON::Boolean;
|
||||
ret.c_value = true;
|
||||
} else if (value == "false") {
|
||||
ret.c_type = PIJSON::Boolean;
|
||||
ret.c_type = PIJSON::Boolean;
|
||||
ret.c_value = false;
|
||||
} else {
|
||||
ret.c_type = PIJSON::Number;
|
||||
ret.c_type = PIJSON::Number;
|
||||
ret.c_value = value;
|
||||
}
|
||||
}
|
||||
@@ -423,14 +423,14 @@ PIJSON PIJSON::parseValue(PIString & s) {
|
||||
|
||||
|
||||
PIJSON PIJSON::parseObject(PIString s) {
|
||||
//piCout << "\n\n\n parseObject" << s;
|
||||
// piCout << "\n\n\n parseObject" << s;
|
||||
PIJSON ret;
|
||||
ret.c_type = PIJSON::Object;
|
||||
while (s.isNotEmpty()) {
|
||||
PIString name = PIJSON::stringUnmask(parseName(s));
|
||||
PIJSON value = parseValue(s);
|
||||
PIJSON value = parseValue(s);
|
||||
auto & child(ret.c_object[name]);
|
||||
child = value;
|
||||
child = value;
|
||||
child.c_name = name;
|
||||
s.trim();
|
||||
if (s.isEmpty()) break;
|
||||
@@ -442,7 +442,7 @@ PIJSON PIJSON::parseObject(PIString s) {
|
||||
|
||||
|
||||
PIJSON PIJSON::parseArray(PIString s) {
|
||||
//piCout << "\n\n\n parseArray" << s;
|
||||
// piCout << "\n\n\n parseArray" << s;
|
||||
PIJSON ret;
|
||||
ret.c_type = PIJSON::Array;
|
||||
while (s.isNotEmpty()) {
|
||||
@@ -468,14 +468,14 @@ PIString PIJSON::stringMask(const PIString & s, bool mask_unicode) {
|
||||
} else {
|
||||
char ca = c.toAscii();
|
||||
switch (ca) {
|
||||
case '"' : ret += "\\\""; break;
|
||||
case '"': ret += "\\\""; break;
|
||||
case '\\': ret += "\\\\"; break;
|
||||
case '/' : ret += "\\/" ; 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 '/': ret += "\\/"; 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;
|
||||
default: ret += ca;
|
||||
}
|
||||
}
|
||||
@@ -493,15 +493,15 @@ PIString PIJSON::stringUnmask(const PIString & s) {
|
||||
++i;
|
||||
char na = s[i].toAscii();
|
||||
switch (na) {
|
||||
case '"' : ret += '\"'; break;
|
||||
case '"': ret += '\"'; break;
|
||||
case '\\': ret += '\\'; break;
|
||||
case '/' : ret += '/' ; 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 'u' :
|
||||
case '/': ret += '/'; 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 'u':
|
||||
ret += PIChar(s.mid(i + 1, 4).toUShort(16));
|
||||
i += 4;
|
||||
break;
|
||||
@@ -517,17 +517,17 @@ PIString PIJSON::stringUnmask(const PIString & s) {
|
||||
|
||||
void PIJSON::print(PIString & s, const PIJSON & v, PIString tab, bool spaces, bool transform, bool comma, bool mask_unicode) {
|
||||
if (spaces) s += tab;
|
||||
/*
|
||||
switch (v.c_type) {
|
||||
case JSONEntry::Invalid: s << "(Invalid)"; break;
|
||||
case JSONEntry::Null: s << "(Null)"; break;
|
||||
case JSONEntry::Boolean: s << "(Boolean)"; break;
|
||||
case JSONEntry::Number: s << "(Number)"; break;
|
||||
case JSONEntry::String: s << "(String)"; break;
|
||||
case JSONEntry::Object: s << "(Object)"; break;
|
||||
case JSONEntry::Array: s << "(Array)"; break;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
switch (v.c_type) {
|
||||
case JSONEntry::Invalid: s << "(Invalid)"; break;
|
||||
case JSONEntry::Null: s << "(Null)"; break;
|
||||
case JSONEntry::Boolean: s << "(Boolean)"; break;
|
||||
case JSONEntry::Number: s << "(Number)"; break;
|
||||
case JSONEntry::String: s << "(String)"; break;
|
||||
case JSONEntry::Object: s << "(Object)"; break;
|
||||
case JSONEntry::Array: s << "(Array)"; break;
|
||||
}
|
||||
*/
|
||||
if (v.name().isNotEmpty()) {
|
||||
s += '"' + (transform ? stringMask(v.name(), mask_unicode) : v.name()) + "\":";
|
||||
if (spaces) s += ' ';
|
||||
@@ -543,8 +543,8 @@ void PIJSON::print(PIString & s, const PIJSON & v, PIString tab, bool spaces, bo
|
||||
if (spaces) s += '\n';
|
||||
{
|
||||
PIString ntab = tab + " ";
|
||||
auto it = v.c_object.makeIterator();
|
||||
int cnt = 0;
|
||||
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(), mask_unicode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user