コード例 #1
0
ファイル: fs.cpp プロジェクト: williame/GlestNG
std::string fs_t::canocial(const std::string& path) const {
	std::string src, cano;
	if(_starts_with(path,pimpl->data_directory))
		src = std::string(path,pimpl->data_directory.size());
	else
		src = path;
	// tidy up and .. and check its not breaking root
	size_t start = 0;
	std::vector<size_t> parts;
	while(true) {
		std::string part = _path_tok(src,start);
		start += part.size();
		if(part == "") break;
		if(part == "/") {
			std::cerr << "in "<<path<<", skipping /" << std::endl;
			continue;
		} else if(part == "../") {
			//### find a test case and we can support it
			data_error(".. not supported in "<<path);
		} else if(part[0] == '.')
			data_error("it is not policy to support hidden files in "<<path);
		parts.push_back(start-part.size()); 
		cano += part;
	}
	return pimpl->data_directory+cano;
}
コード例 #2
0
ファイル: fs.cpp プロジェクト: williame/GlestNG
std::string fs_t::join(const std::string& path,const std::string& sub) const {
	if(_starts_with(sub,pimpl->data_directory))
		return canocial(sub);
	const char* s = sub.c_str();
	while((*s=='\\')||(*s=='/')) s++;
	if(is_dir(path))
		return canocial(path+'/'+s);
	return canocial(parent_directory(path)+'/'+s);
}
コード例 #3
0
ファイル: player_list.cpp プロジェクト: BizarreCake/hCraft
	/* 
	 * Searches the player list for a player that has the specified name.
	 * Uses the given method to determine if names match.
	 */
	player*
	player_list::find (const char *name, player_find_method method)
	{
		std::lock_guard<std::mutex> guard {this->lock};
		
		switch (method)
			{
				case player_find_method::case_sensitive:
					{
						auto itr = this->players.find (name);
						if (itr != this->players.end ())
							{
								// do another comparison, this time with case sensitivity.
								if (std::strcmp (itr->first.c_str (), name) == 0)
									return itr->second;
							}
						
						return nullptr;
					}
				
				case player_find_method::case_insensitive:
					{
						auto itr = this->players.find (name);
						if (itr != this->players.end ())
							return itr->second;
						
						return nullptr;
					}
				
				case player_find_method::name_completion:
					{
						std::vector<player *> matches;
						for (auto itr = this->players.begin (); itr != this->players.end (); ++itr)
							{
								if (_starts_with (itr->first.c_str (), name))
									matches.push_back (itr->second);
							}
						if (matches.empty ())
							return nullptr;
						return matches.front ();
					}
			}
		
		// never reached.
		return nullptr;
	}
コード例 #4
0
ファイル: fs.cpp プロジェクト: williame/GlestNG
std::string fs_t::pimpl_t::resolve(const std::string& path) {
	if(!_starts_with(path,data_directory))
		panic("expecting "<<path<<" to be in "<<data_directory);
	resolve_t::iterator i=resolved.find(path);
	data_error(path << " does not exist!");
}