Ejemplo n.º 1
0
	int TablePaser::GetLine(std::basic_istream<char>& in_put, vector<string>& columns)
	{
		if (in_put.eof())
			return -1;

		std::streamoff i = in_put.tellg();
		memset(LineData, 0, LINE_DATA_MAX);
		in_put.getline(LineData, LINE_DATA_MAX);
		char* r_ch = strchr(LineData, '\r');
		if (r_ch)
		{
			in_put.seekg(i + (r_ch - LineData) + 1);
			*r_ch = '\0';
		}

		if (strlen(LineData) == 0)
			return GetLine(in_put, columns);

		stringstream ss_str;
		ss_str << LineData;

		int ret = 1;
		string column;
		while (ret == 1)
		{
			if ((ret = GetColumn(ss_str, in_put, column)) == -1)
				break;
			columns.push_back(column);
		}
		if (in_put.eof())
			return 0;
		return 1;
	}
Ejemplo n.º 2
0
	int TablePaser::GetColumn(stringstream& ss_str, std::basic_istream<char>& in_put, string& column)
	{
		column = "";
		if (ss_str.eof())
			return -1;
		char cur_char[2];
		cur_char[1] = 0;
		char separator = '	';

		if (ss_str.get(cur_char[0]).eof())
			return 1;
		if (cur_char[0] == '	')
			return 1;
		else if (cur_char[0] == '"')
			separator = '"';
		else
			column += string(cur_char);


		while (1)
		{
			if (ss_str.eof())
			{
				if (separator == '"')
				{
					if (in_put.eof())
						return 0;

					column += string("\n\0");
					ss_str.clear();
					in_put.getline(LineData, LINE_DATA_MAX);
					ss_str << LineData;
				}
				else
					return 0;
			}
			ss_str.getline(LineData, 4096, separator);
			column += LineData;
			//column.append(LineData);
			if (ss_str.eof())
				continue;
			if (separator == '	')
				return 1;
			else if (separator == '"')
			{
				if (ss_str.eof())
					return 0;
				ss_str.get(cur_char[0]);
				if (ss_str.eof())
					return 1;
				else if (cur_char[0] == '	')
					return 1;
				else if (cur_char[0] != separator)
					separator = '	';
				//column.push_back(cur_char);
				column += string(cur_char);
			}
		}
		return -1;
	}
void CDataSerializer::Read(std::basic_istream<char>& sStream, CData* pData)
{
	if (!sStream.good())
		return;

	if (!pData)
		return;

	char szLine[1024];
	string sLine;

	CData* pCurrentData = pData;
	CData* pLastData = NULL;

	while (sStream.getline(szLine, 1024))
	{
		sLine = string(szLine);

		size_t iComment = sLine.find("//");
		if (iComment != string::npos)
			sLine = sLine.substr(0, iComment);

		sLine = trim(sLine);

		if (sLine.length() == 0)
			continue;

		if (sLine[0] == '{')
		{
			pCurrentData = pLastData;
			continue;
		}

		if (sLine[0] == '}')
		{
			pCurrentData = pCurrentData->GetParent();
			continue;
		}

		vector<string> asTokens;
		explode(sLine, asTokens, ":");

		if (asTokens.size() == 1)
			pLastData = pCurrentData->AddChild(trim(sLine));
		else if (asTokens.size() >= 2)
			pLastData = pCurrentData->AddChild(trim(asTokens[0]), trim(sLine.substr(sLine.find(':')+1)));
	}
}