本文整理汇总了C++中Groups::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Groups::insert方法的具体用法?C++ Groups::insert怎么用?C++ Groups::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Groups
的用法示例。
在下文中一共展示了Groups::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
bool MLogicalValuesPrivate::parse(const QFileInfo &fileInfo, Groups &groups)
{
QFile file(fileInfo.filePath());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
QByteArray group = "General";
groups.insert("General", Values());
while (!file.atEnd()) {
QByteArray line = file.readLine().trimmed();
// skip comments
if (line.startsWith("[")) {
// parse group header
int index = line.indexOf("]", 1);
if (index == -1) {
mWarning("MLogicalValues") << "Error occurred when parsing .ini file:" << line;
file.close();
return false;
}
// this will be the currently active group
group = line.mid(1, index - 1);
} else {
// key/value pair
QByteArray key, value;
QByteArray *target = &key;
// stores the last 'good' character
int truncation = 0;
// go through whole line
for (int i = 0; i < line.length(); i++) {
QChar character = line.at(i);
if (character == ';') {
break;
} else if (character == '=') {
// remove trailing whitespaces
target->truncate(truncation);
// start to parse value
target = &value;
truncation = 0;
} else {
if (target->isEmpty() && character.isSpace()) {
// do not add whitespaces at the beginning
} else {
(*target) += character;
if (!character.isSpace())
truncation = target->length();
}
}
}
// remove trailing whitespaces
target->truncate(truncation);
// consistency check
if (!line.startsWith(';') && line.length() > 0) {
if (key.isEmpty() || value.isEmpty()) {
mWarning("MLogicalValues") << "Error occurred when parsing .ini file:" << line;
file.close();
return false;
}
// store
Values &values = groups[group];
if (!values.contains(key)) {
values.insert(key, value);
}
}
}
}
saveToBinaryCache(fileInfo, groups);
file.close();
return true;
}