PIConfig multiline support
This commit is contained in:
@@ -249,7 +249,7 @@ void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const {
|
||||
|
||||
void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
||||
PIString nl = p + " ";
|
||||
if (!_value.isEmpty()) s << p << _name << " = " << _value << PICoutManipulators::NewLine;
|
||||
if (!_value.isEmpty()) s << p << _name << " = " << _value << " (" << _type << " " << _comment << ")" << PICoutManipulators::NewLine;
|
||||
else std::cout << p << _name << std::endl;
|
||||
piForeachC (Entry * i, _children) i->piCoutt(s, nl);
|
||||
}
|
||||
@@ -261,6 +261,7 @@ PIConfig::PIConfig(const PIString & path, PIIODevice::DeviceMode mode) {
|
||||
dev = new PIFile(path, mode);
|
||||
if (!dev->isOpened())
|
||||
dev->open(path, mode);
|
||||
incdirs << PIFile::fileInfo(path).dir();
|
||||
parse();
|
||||
}
|
||||
|
||||
@@ -277,7 +278,11 @@ PIConfig::PIConfig(PIIODevice * device, PIIODevice::DeviceMode mode) {
|
||||
_init();
|
||||
own_dev = false;
|
||||
dev = device;
|
||||
if (dev) dev->open(mode);
|
||||
if (dev) {
|
||||
dev->open(mode);
|
||||
if (PIString(dev->className()) == "PIFile")
|
||||
incdirs << PIFile::fileInfo(((PIFile*)dev)->path()).dir();
|
||||
}
|
||||
parse();
|
||||
}
|
||||
|
||||
@@ -716,9 +721,9 @@ void PIConfig::parse() {
|
||||
//piCout << "[PIConfig] charset" << PIFile::defaultCharset();
|
||||
PIString src, str, tab, comm, all, name, type, prefix, tprefix;
|
||||
PIStringList tree;
|
||||
Entry * entry, * te, * ce;
|
||||
Entry * entry = 0, * te = 0, * ce = 0;
|
||||
int ind, sind;
|
||||
bool isNew, isPrefix;
|
||||
bool isNew = false, isPrefix = false, wasMultiline = false, isMultiline = false;
|
||||
piForeach (PIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
@@ -739,27 +744,44 @@ void PIConfig::parse() {
|
||||
//piCout << "line \"" << str << "\"";
|
||||
tab = str.left(str.find(str.trimmed().left(1)));
|
||||
str.trim();
|
||||
//cout << endl << str << endl << endl;
|
||||
// piCout << "[PIConfig] str" << str.size() << str << str.toUTF8();
|
||||
all = str;
|
||||
|
||||
sind = str.find('#');
|
||||
if (sind > 0) {
|
||||
comm = str.mid(sind + 1).trimmed();
|
||||
if (!comm.isEmpty()) {
|
||||
type = comm[0];
|
||||
comm.cutLeft(1).trim();
|
||||
} else type = "s";
|
||||
str = str.left(sind).trim();
|
||||
} else {
|
||||
type = "s";
|
||||
comm = "";
|
||||
}
|
||||
|
||||
if (str.endsWith("\\")) {
|
||||
isMultiline = true;
|
||||
str.cutRight(1).trim();
|
||||
} else
|
||||
isMultiline = false;
|
||||
|
||||
if (wasMultiline) {
|
||||
wasMultiline = false;
|
||||
if (ce) {
|
||||
ce->_value += str;
|
||||
ce->_all += "\\\n" + all;
|
||||
}
|
||||
str.clear();
|
||||
}
|
||||
wasMultiline = isMultiline;
|
||||
|
||||
//piCout << "[PIConfig] str" << str.size() << str << str.toUTF8();
|
||||
ind = str.find('=');
|
||||
if ((ind > 0) && (str[0] != '#')) {
|
||||
sind = str.find('#');
|
||||
if (sind > 0) {
|
||||
comm = str.right(str.length() - sind - 1).trimmed();
|
||||
if (comm.length() > 0) type = comm[0];
|
||||
else type = "s";
|
||||
comm = comm.right(comm.length() - 1).trimmed();
|
||||
str = str.left(sind);
|
||||
} else {
|
||||
type = "s";
|
||||
comm = "";
|
||||
}
|
||||
|
||||
//name = str.left(ind).trimmed();
|
||||
tree = (prefix + str.left(ind).trimmed()).split(delim);
|
||||
if (tree.front() == "include") {
|
||||
name = str.right(str.length() - ind - 1).trimmed();
|
||||
name = str.mid(ind + 1).trimmed();
|
||||
PIConfig * iconf = new PIConfig(name, incdirs);
|
||||
//piCout << "include" << name << iconf->dev;
|
||||
if (!iconf->dev) {
|
||||
@@ -797,7 +819,7 @@ void PIConfig::parse() {
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_name = name;
|
||||
ce->_value = str.right(str.length() - ind - 1).trimmed();
|
||||
ce->_value = str.mid(ind + 1).trimmed();
|
||||
ce->_type = type;
|
||||
ce->_comment = comm;
|
||||
//piCout << "[PIConfig] comm" << comm.size() << comm << comm.toUTF8();
|
||||
|
||||
Reference in New Issue
Block a user