code format
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIValueTree conversions
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
PIValueTree conversions
|
||||
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 "pivaluetree_conversions.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "pijson.h"
|
||||
|
||||
#include "pifile.h"
|
||||
#include "piiostring.h"
|
||||
#include "piiostream.h"
|
||||
#include "piiostring.h"
|
||||
#include "pijson.h"
|
||||
#include "pipropertystorage.h"
|
||||
|
||||
const char _attribute_[] = "_attribute_";
|
||||
|
||||
@@ -29,8 +30,7 @@ PIString unmask(const PIString & str) {
|
||||
PIString ret(str);
|
||||
ret.unmask("#\\");
|
||||
if (ret.isNotEmpty())
|
||||
if (ret[0] == '\\')
|
||||
ret.remove(0);
|
||||
if (ret[0] == '\\') ret.remove(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ PIString mask(const PIString & str) {
|
||||
PIString ret = str;
|
||||
if (ret.isEmpty()) return ret;
|
||||
ret.mask("#\\");
|
||||
if (ret[0].isSpace())
|
||||
ret.insert(0, '\\');
|
||||
if (ret[0].isSpace()) ret.insert(0, '\\');
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -74,7 +73,7 @@ PIValueTree fromJSONTree(const PIJSON & json) {
|
||||
ret.setName(json["name"].toString());
|
||||
ret.setComment(json["comment"].toString());
|
||||
PIString value_str = json["value"].toString();
|
||||
PIVariant value = PIVariant::fromType(json["type"].toString());
|
||||
PIVariant value = PIVariant::fromType(json["type"].toString());
|
||||
if (value_str.isNotEmpty()) {
|
||||
if (value.isValid())
|
||||
value.setValueFromString(value_str);
|
||||
@@ -86,7 +85,7 @@ PIValueTree fromJSONTree(const PIJSON & json) {
|
||||
for (const auto & i: attr.object())
|
||||
ret.attributes()[i.first] = i.second.value();
|
||||
bool is_array = ret.isArray();
|
||||
int chindex = 0;
|
||||
int chindex = 0;
|
||||
const PIJSON & chl(json["children"]);
|
||||
for (const auto & i: chl.array()) {
|
||||
PIValueTree c = fromJSONTree(i);
|
||||
@@ -120,8 +119,7 @@ PIValueTree prepareFromText(const PIValueTree & root) {
|
||||
value.setValueFromString(root.value().toString());
|
||||
ret.setValue(value);
|
||||
for (const auto & c: root.children()) {
|
||||
if (c.name() != _attribute_)
|
||||
ret[c.name()] = prepareFromText(c);
|
||||
if (c.name() != _attribute_) ret[c.name()] = prepareFromText(c);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -144,7 +142,7 @@ PIValueTree PIValueTreeConversions::fromText(PIIODevice * device) {
|
||||
continue;
|
||||
}
|
||||
line += l;
|
||||
//piCout << "L" << line.replacedAll("\n", "\\n");
|
||||
// piCout << "L" << line.replacedAll("\n", "\\n");
|
||||
if (line.size() < 2) {
|
||||
line.clear();
|
||||
continue;
|
||||
@@ -169,11 +167,13 @@ PIValueTree PIValueTreeConversions::fromText(PIIODevice * device) {
|
||||
cind = ind;
|
||||
}
|
||||
if (cind >= 0) {
|
||||
comm = line.takeMid(cind + 1);
|
||||
comm = line.takeMid(cind + 1);
|
||||
bool typed = false;
|
||||
if (comm.isNotEmpty()) {
|
||||
if (comm.size() == 1) typed = true;
|
||||
else if (comm[0].isAlpha() && comm[1].isSpace()) typed = true;
|
||||
if (comm.size() == 1)
|
||||
typed = true;
|
||||
else if (comm[0].isAlpha() && comm[1].isSpace())
|
||||
typed = true;
|
||||
}
|
||||
if (typed) {
|
||||
switch (comm.takeLeft(1)[0].toAscii()) {
|
||||
@@ -202,11 +202,11 @@ PIValueTree PIValueTreeConversions::fromText(PIIODevice * device) {
|
||||
PIConfig * iconf = new PIConfig(name, incdirs);
|
||||
//piCout << "include" << name << iconf->dev;
|
||||
if (!iconf->dev) {
|
||||
delete iconf;
|
||||
delete iconf;
|
||||
} else {
|
||||
inc_devs << iconf;
|
||||
includes << iconf << iconf->includes;
|
||||
updateIncludes();
|
||||
inc_devs << iconf;
|
||||
includes << iconf << iconf->includes;
|
||||
updateIncludes();
|
||||
}
|
||||
other.back() = src;*/
|
||||
}
|
||||
@@ -214,29 +214,25 @@ PIValueTree PIValueTreeConversions::fromText(PIIODevice * device) {
|
||||
line.clear();
|
||||
continue;
|
||||
}
|
||||
//piCout << path << line << comm;
|
||||
// piCout << path << line << comm;
|
||||
PIValueTree & leaf(ret[path]);
|
||||
leaf.setComment(comm);
|
||||
leaf.setValue(unmask(line));
|
||||
if (!path.contains(_attribute_))
|
||||
if (!leaf.contains({_attribute_, "type"}))
|
||||
leaf[_attribute_].addChild({"type", type});
|
||||
if (!leaf.contains({_attribute_, "type"})) leaf[_attribute_].addChild({"type", type});
|
||||
line.clear();
|
||||
}
|
||||
return prepareFromText(ret);
|
||||
//return ret;
|
||||
// return ret;
|
||||
}
|
||||
|
||||
|
||||
PIJSON toJSONTree(const PIValueTree & root, PIValueTreeConversions::Options options) {
|
||||
PIJSON ret = PIJSON::newObject();
|
||||
if (root.name().isNotEmpty())
|
||||
ret["name"] = root.name();
|
||||
if (root.comment().isNotEmpty() && options[PIValueTreeConversions::WithComment])
|
||||
ret["comment"] = root.comment();
|
||||
if (root.name().isNotEmpty()) ret["name"] = root.name();
|
||||
if (root.comment().isNotEmpty() && options[PIValueTreeConversions::WithComment]) ret["comment"] = root.comment();
|
||||
if (root.value().isValid()) {
|
||||
if (options[PIValueTreeConversions::WithType])
|
||||
ret["type"] = root.value().typeName();
|
||||
if (options[PIValueTreeConversions::WithType]) ret["type"] = root.value().typeName();
|
||||
ret["value"] = root.value().toString();
|
||||
}
|
||||
if (root.attributes().isNotEmpty() && options[PIValueTreeConversions::WithAttributes]) {
|
||||
@@ -286,8 +282,7 @@ PIString toTextTree(const PIValueTree & root, PIString prefix, PIValueTreeConver
|
||||
prefix += root.name();
|
||||
if (root.hasChildren()) {
|
||||
ret += "\n[" + prefix + "]\n";
|
||||
if (root.isArray() && options[PIValueTreeConversions::WithAttributes])
|
||||
ret += toTextTreeAttributes(root, "", options);
|
||||
if (root.isArray() && options[PIValueTreeConversions::WithAttributes]) ret += toTextTreeAttributes(root, "", options);
|
||||
for (const auto & c: root.children()) {
|
||||
PIString cp = prefix;
|
||||
ret += toTextTree(c, prefix, options);
|
||||
@@ -302,8 +297,7 @@ PIString toTextTree(const PIValueTree & root, PIString prefix, PIValueTreeConver
|
||||
ret += root.comment();
|
||||
}
|
||||
ret += "\n";
|
||||
if (options[PIValueTreeConversions::WithAttributes])
|
||||
ret += toTextTreeAttributes(root, root.name() + ".", options);
|
||||
if (options[PIValueTreeConversions::WithAttributes]) ret += toTextTreeAttributes(root, root.name() + ".", options);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user