code format
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
#include "cdutils_parser.h"
|
||||
|
||||
#include "cdutils_types.h"
|
||||
#include "piiostring.h"
|
||||
#include "piiobytearray.h"
|
||||
#include "pifile.h"
|
||||
#include "piiobytearray.h"
|
||||
#include "piiostring.h"
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
@@ -63,14 +64,14 @@ PIVector<int> enumValues(const PIString & e, const PIMap<PIString, CDSection> &
|
||||
PIVector<int> ret;
|
||||
enames.clear();
|
||||
if (sections.contains(e)) {
|
||||
ret = sections.at(e).indexes();
|
||||
ret = sections.at(e).indexes();
|
||||
enames = sections.at(e).index_names();
|
||||
} else {
|
||||
int v = e.toInt();
|
||||
if (v < 2) return ret;
|
||||
for (int i = 0; i < v; ++i) {
|
||||
ret << i;
|
||||
enames << "";//PIString::fromNumber(i);
|
||||
enames << ""; // PIString::fromNumber(i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -81,7 +82,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
CDType::cdT et = (CDType::cdT)cdsection_type;
|
||||
if (!d) return CDSection(et);
|
||||
if (!d->canRead()) return CDSection(et);
|
||||
//piCout << "[CDSection] parse start";
|
||||
// piCout << "[CDSection] parse start";
|
||||
CDSection cs(et);
|
||||
CDType ck;
|
||||
PIMap<PIString, CDSection> sections;
|
||||
@@ -89,14 +90,14 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
PIString content, line, alias, type, comment;
|
||||
PIStringList iarr;
|
||||
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) {
|
||||
PIByteArray c = ((PIFile*)d)->readAll();
|
||||
PIByteArray c = ((PIFile *)d)->readAll();
|
||||
c << uchar(0);
|
||||
content = PIString::fromUTF8((const char *)c.data());
|
||||
}
|
||||
if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string());
|
||||
if (PIStringAscii(d->className()) == PIStringAscii("PIIOByteArray")) content = PIString(*(((PIIOByteArray*)d)->byteArray()));
|
||||
if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString *)d)->string());
|
||||
if (PIStringAscii(d->className()) == PIStringAscii("PIIOByteArray")) content = PIString(*(((PIIOByteArray *)d)->byteArray()));
|
||||
PIIOString ios(&content);
|
||||
//int phase = 0;
|
||||
// int phase = 0;
|
||||
int cind = -1;
|
||||
while ((cind = content.find("enum", cind)) >= 0) {
|
||||
ios.seek(cind);
|
||||
@@ -114,11 +115,11 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
cind += 4;
|
||||
continue;
|
||||
}
|
||||
cs = CDSection(et);
|
||||
cs = CDSection(et);
|
||||
cs.name = line;
|
||||
//piCout << "enum" << cs.name;
|
||||
// piCout << "enum" << cs.name;
|
||||
int cev = 0;
|
||||
// cevalues.clear();
|
||||
// cevalues.clear();
|
||||
while (!ios.isEnd()) {
|
||||
line = ios.readLine().trim();
|
||||
comment.clear();
|
||||
@@ -128,7 +129,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
if (comment.find("=") >= 0) {
|
||||
parseInsert(comment, alias, iarr);
|
||||
if (!iarr.isEmpty()) {
|
||||
// piCout << "#" << enum_values;
|
||||
// piCout << "#" << enum_values;
|
||||
if (!enum_values.contains(alias)) {
|
||||
piCout << "Parse error: can`t find section alias \"" << alias << "\"!";
|
||||
return CDSection(et);
|
||||
@@ -137,16 +138,16 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!";
|
||||
return CDSection(et);
|
||||
}
|
||||
//piCout << "insert" << alias << iarr;
|
||||
int aval = enum_values.value(alias);
|
||||
// piCout << "insert" << alias << iarr;
|
||||
int aval = enum_values.value(alias);
|
||||
CDSection is = sections.value(iarr.take_front()), ts;
|
||||
int ibpos = is.name.size_s();
|
||||
piForeachRC (PIString & a, iarr) {
|
||||
int ibpos = is.name.size_s();
|
||||
piForeachRC(PIString & a, iarr) {
|
||||
PIStringList enames;
|
||||
PIVector<int> evals = enumValues(a, sections, enames);
|
||||
//piCout << a << evals;
|
||||
// piCout << a << evals;
|
||||
for (int i = 0; i < evals.size_s(); ++i) {
|
||||
ts.section(evals[i]) = is;
|
||||
ts.section(evals[i]) = is;
|
||||
ts.section(evals[i]).alias = enames[i];
|
||||
}
|
||||
ts.name = is.name;
|
||||
@@ -154,13 +155,13 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
is = ts;
|
||||
ts = CDSection(et);
|
||||
}
|
||||
is.alias = alias;
|
||||
is.alias = alias;
|
||||
cs.section(aval) = is;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
parseEnumLine(line, &cev, &type, &comment);
|
||||
//piCout << line << "=" << cev << "//" << type << comment;
|
||||
// piCout << line << "=" << cev << "//" << type << comment;
|
||||
ck = CDType(cev, line, type, "", "", comment, et);
|
||||
if (type == "e") {
|
||||
if (comment.startsWith("${")) {
|
||||
@@ -169,22 +170,22 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
comment.cutLeft(en.size_s() + 2).trim();
|
||||
ck.setEnumValues(sections.value(en).enumValues());
|
||||
ck.setComment(comment);
|
||||
//piCout << "enum" << en << ck.enumValues();
|
||||
// piCout << "enum" << en << ck.enumValues();
|
||||
}
|
||||
}
|
||||
cs[cev] = ck;
|
||||
//cevalues[line] = cev;
|
||||
cs[cev] = ck;
|
||||
// cevalues[line] = cev;
|
||||
enum_values[line] = cev;
|
||||
++cev;
|
||||
}
|
||||
}
|
||||
//piCout << cs.name << cs.k;
|
||||
// piCout << cs.name << cs.k;
|
||||
sections[cs.name] = cs;
|
||||
// piCout << "#" << cevalues;
|
||||
// enum_values << cevalues;
|
||||
// piCout << "#" << cevalues;
|
||||
// enum_values << cevalues;
|
||||
cind += 4;
|
||||
}
|
||||
// piCout << "[CDSection] parse end";
|
||||
// piCout << "[CDSection] parse end";
|
||||
switch (et) {
|
||||
case CDType::cdK: return sections.value("KDescription");
|
||||
case CDType::cdX: return sections.value("XDescription");
|
||||
|
||||
Reference in New Issue
Block a user