bool parse(StreamReader stream)
{
string szLine;
string curIndex = "";//当前索引值
char[] char_1 = new char[1] { '#' };
char[] char_2 = new char[2] { '[', ']' };
char[] char_3 = new char[] { '=' };
//Dictionary<string, string> CurrentSection = new Dictionary<string, string>();
while (!stream.EndOfStream)
{
szLine = stream.ReadLine();
//字符串不能为null
if (string.IsNullOrEmpty(szLine))
{
continue;
}
//截取#开头前面的有用字符
string[] str = szLine.Split(char_1);
szLine = str[0];
//字符串不能为null
if (string.IsNullOrEmpty(szLine))
{
continue;
}
//如果是索引[**]
if (szLine[0] == '[')
{
if (!(szLine[szLine.Length - 1] == ']') || szLine.Length <= 2)
{
return false;
}
string[] strsplit = szLine.Split(char_2);
curIndex = strsplit[1];
m_SectiontList.Add(curIndex.Trim(), new Dictionary<string, string>());
}
else
{
if (string.IsNullOrEmpty(curIndex))
{
return false;
}
string[] strsplit = szLine.Split(char_3);
if (string.IsNullOrEmpty(strsplit[0]) || string.IsNullOrEmpty(strsplit[0]) || strsplit.Length > 2)
{
return false;
}
m_SectiontList[curIndex].Add(strsplit[0].ToString().Trim(), strsplit[1].ToString().Trim());
}
}
return true;
}