Пример #1
0
	void WtsReader::Read(buffer_reader& reader, WtsTable& table)
	{
		WST_READER_STATE::STATE state = WST_READER_STATE::STATE_HEADER;
		uint32_t key = 0;
		std::string value;

		reader::utility::remove_bom(reader);
		reader::utility::each_line(reader, [&](boost::string_ref& line)
		{
			switch (state)
			{
			case WST_READER_STATE::STATE_HEADER:
				{
					trim_left(line, ctype::is_space());
					if (line.substr(0, 6) == "STRING")
					{
						line.remove_prefix(6);
						trim(line, ctype::is_space());
						key = Str2UInt(line);
						state = WST_READER_STATE::STATE_BEGIN;
					}
				}
				break;
			case WST_READER_STATE::STATE_BEGIN:
				{
					trim_left(line, ctype::is_space());
					if (!line.empty() && '{' == line[0])
					{
						state = WST_READER_STATE::STATE_BODY;
					}
				}
				break;
			case WST_READER_STATE::STATE_BODY:
				{
					boost::string_ref new_line = trim_left_copy(line, ctype::is_space());
					if (new_line.empty() || ('}' != new_line[0]))
					{
						value.append(line.begin(), line.end());
					}
					else
					{
						while ((!value.empty()) && ((*value.rbegin() == '\n') || (*value.rbegin() == '\r')))
						{
							value.pop_back();
						}

						table[key] = value;
						value.clear();
						state = WST_READER_STATE::STATE_HEADER;
					}
				}
				break;
			default:
				break;
			}
		}
		);
	}
Пример #2
0
bool StrSplit(std::string& src, std::list<uint32>& strList, std::string sep)
{
	std::string s;
	for (std::string::const_iterator i = src.begin(); i != src.end(); i++)
	{
		if (sep.find(*i) != std::string::npos)
		{
			if (s.length()) strList.push_back(Str2UInt(s.c_str()));
			s = "";
		}
		else
		{
			s += *i;
		}
	}
	if (s.length()) strList.push_back(Str2UInt(s.c_str()));
	return true;
}
Пример #3
0
	const std::string& WtsConverter::Convert(const std::string& str)
	{
		_Mybase::initialize("war3map.wts");

		if (0 == str.compare(0, _countof("TRIGSTR_") - 1, "TRIGSTR_"))
		{
			uint32_t index = Str2UInt(str.substr(_countof("TRIGSTR_") - 1));
			auto It = _Mybase::table_.find(index);
			if (It != _Mybase::table_.end())
			{
				return  It->second;
			}
		}

		return str;
	}