コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: IniHandler.cs プロジェクト: viticm/pap2
		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;
		}