Пример #1
0
ConfigFile::ConfigFile(std::string const& configFile) {
	std::ifstream file(configFile.c_str());

	std::string line;
	std::string name;
	std::string value;
	std::string inSection;
	int posEqual;
	while (safeGetline(file, line)) {

		if (!line.length()) continue;

		if (line[0] == '#') continue;
		if (line[0] == ';') continue;

		if (line[0] == '[') {
			inSection = trim(line.substr(1, line.find(']') - 1));
			continue;
		}

		posEqual = line.find('=');
		name = trim(line.substr(0, posEqual));
		value = trim(line.substr(posEqual + 1));

		content_[inSection + '/' + name] = Chameleon(value);
	}
}
Пример #2
0
Chameleon const& ConfigFile::Value(std::string const& section, std::string const& entry, std::string const& value) {
  try {
    return Value(section, entry);
  } catch(const char *) {
    return content_.insert(std::make_pair(section+'/'+entry, Chameleon(value))).first->second;
  }
}