示例#1
0
文件: xml.cpp 项目: logzero/vdrift
static void read_xml(std::istream & in, PTree & node, Include * include, std::string key)
{
	std::string line, escape("/"+node.value());
	while (in.good())
	{
		std::getline(in, line, '\n');
		if (line.empty())
		{
			continue;
		}

		size_t begin = line.find_first_not_of(" \t\n<");
		size_t end = line.length();
		if (begin >= end || line[begin] == '!')
		{
			continue;
		}

		line = line.substr(begin, end);

		if (line.find(escape) == 0)
		{
			break;
		}

		if (key.length() == 0)
		{
			end = line.find(" ");
			key = line.substr(0, end);
			continue;
		}

		size_t next = line.find("</"+key);
		if (next < end)
		{
			// New property.
			std::string value = line.substr(0, next);

			// Include?
			if (include && key == "include")
			{
				(*include)(node, value);
			}
			else
			{
				node.set(key, value);
			}
		}
		else
		{
			// New node.
			end = line.find(" ");
			std::string child_key = line.substr(0, end);
			read_xml(in, node.set(key, PTree()), include, child_key);
		}
		key.clear();
	}
}
示例#2
0
bool read_ini(const std::string & file_name, const file_open & fopen, PTree & p)
{
	p.value() = file_name;
	std::istream * in = fopen(file_name);
	if (in->good())
	{
		ini reader(*in, p, &fopen);
		reader.read();
		delete in;
		return true;
	}
	delete in;
	return false;
}
示例#3
0
static void read_xml(std::istream & in, PTree & p, std::string key)
{
	std::string line, escape("/"+p.value());
	while (in.good())
	{
		std::getline(in, line, '\n');
		if (line.empty())
		{
			continue;
		}

		size_t begin = line.find_first_not_of(" \t\n<");
		size_t end = line.length();
		if (begin >= end || line[begin] == '!')
		{
			continue;
		}

		line = line.substr(begin, end);

		if (line.find(escape) == 0)
		{
			break;
		}

		if (key.length() == 0)
		{
			end = line.find(" ");
			key = line.substr(0, end);
			continue;
		}

		size_t next = line.find("</"+key);
		if (next < end)
		{
			std::string value = line.substr(0, next);
			p.set(key, value);
		}
		else
		{
			end = line.find(" ");
			std::string child_key = line.substr(0, end);
			read_xml(in, p.set(key, PTree()), child_key);
		}
		key.clear();
	}
}