public static IniStructure InterpretIni(string Data) { IniStructure IniData = new IniStructure(); string[] Lines = RemoveAndVerifyIni(DivideToLines(Data)); // Divides the Data in lines, removes comments and empty lines // and verifies if the ini is not corrupted // Returns null if it is. if (Lines == null) { return(null); } if (IsLineACategoryDef(Lines[0]) != LineType.Category) { return(null); // Ini is faulty - does not begin with a categorydef } string CurrentCategory = ""; foreach (string line in Lines) { switch (IsLineACategoryDef(line)) { case LineType.Category: // the line is a correct category definition string NewCat = line.Substring(1, line.Length - 2); IniData.AddCategory(NewCat); // adds the category to the IniData CurrentCategory = NewCat; break; case LineType.NotACategory: // the line is not a category definition string[] keyvalue = GetDataFromLine(line); IniData.AddValue(CurrentCategory, keyvalue[0], keyvalue[1]); // Adds the key-value to the current category break; case LineType.Faulty: // the line is faulty return(null); } } return(IniData); }
public static IniStructure InterpretIni(string Data) { IniStructure IniData = new IniStructure(); string[] Lines = RemoveAndVerifyIni(DivideToLines(Data)); // Divides the Data in lines, removes comments and empty lines // and verifies if the ini is not corrupted // Returns null if it is. if (Lines == null) return null; if (IsLineACategoryDef(Lines[0]) != LineType.Category) { return null; // Ini is faulty - does not begin with a categorydef } string CurrentCategory = ""; foreach (string line in Lines) { switch (IsLineACategoryDef(line)) { case LineType.Category: // the line is a correct category definition string NewCat = line.Substring(1,line.Length - 2); IniData.AddCategory(NewCat); // adds the category to the IniData CurrentCategory = NewCat; break; case LineType.NotACategory: // the line is not a category definition string[] keyvalue = GetDataFromLine(line); IniData.AddValue(CurrentCategory, keyvalue[0], keyvalue[1]); // Adds the key-value to the current category break; case LineType.Faulty: // the line is faulty return null; } } return IniData; }