예제 #1
0
void Config::set(PMap &a, const PMap &b, bool merge) {
	if(!merge) {
		a.clear();
		a = b;
		return;
	}
	for(PMap::const_iterator i = b.begin(); i != b.end(); ++i) {
		a.insert(*i);
	}
}
예제 #2
0
bool Config::loadSetting(const std::string &line, const std::string &name, PMap &var) const {
	size_t i = isSetting(line, name, "=");
	if(i != std::string::npos) {
		size_t j = line.find(':', i);
		if(j == std::string::npos) { return false; }
		var.clear();
		var.insert(PMap::value_type(
			trim(line.substr(i, j - i)),
			trim(line.substr(j + 1))
		));
		return true;
	}
	i = isSetting(line, name, "+=");
	if(i != std::string::npos) {
		size_t j = line.find(':', i);
		if(j == std::string::npos) { return false; }
		var.insert(PMap::value_type(
			trim(line.substr(i, j - i)),
			trim(line.substr(j + 1))
		));
		return true;
	}
	i = isSetting(line, name, "-=");
	if(i != std::string::npos) {
		size_t j = line.find(':', i);
		if(j == std::string::npos) { return false; }
		PMap::iterator a = var.find(PMap::value_type(
			trim(line.substr(i, j - i)),
			trim(line.substr(j + 1))
		));
		if(a != var.end()) {
			var.erase(a);
		}
		return true;
	}
	return false;
}