Example #1
0
void GProfile::ProfileParse(const char *szBuffer, __int64 dwSize)
{
	GProfileSection *pSection = 0;

	// parse the file
	__int64 nIdx = 0;

	GString strLine;
	while (nIdx < dwSize)
	{
		GetLine(strLine, szBuffer, &nIdx, dwSize);

		strLine.TrimRightWS();
		strLine.TrimLeftWS();

		if ((strLine.IsEmpty()) || (strLine.GetAt(0) == ';'))
			continue;


		strLine.Replace("\\n", '\n');

		if (strLine.GetAt(0) == '[')
		{
			__int64 nIdx = strLine.Find(']');
			if (nIdx == -1)
				nIdx = strLine.Length();

			// new section
			pSection = new GProfileSection;
			pSection->m_strName = strLine.Mid(1, nIdx - 1);
			pSection->m_strName.TrimLeftWS();
			pSection->m_strName.TrimRightWS();

			m_lstSections.AddLast(pSection);
		}
		else if (pSection)
		{
			__int64 nIdx = strLine.Find('=');
			if (nIdx == -1)
				continue;
			GProfileEntry *pNVP = new GProfileEntry;
			pSection->m_lstNVP.AddLast(pNVP);
			pNVP->m_strName = strLine.Left(nIdx);
			pNVP->m_strName.TrimLeftWS();
			pNVP->m_strName.TrimRightWS();
			
			pNVP->m_strValue = strLine.Mid(nIdx + 1);
			pNVP->m_strValue.TrimLeftWS();
			pNVP->m_strValue.TrimRightWS();
		}
	}
	m_bCached = true;
}