Beispiel #1
0
        public static IniFileElement ParseLine(string line)
        {
            if (line == null)
            {
                return(null);
            }
            if (line.Contains("\n"))
            {
                throw new ArgumentException("String passed to the ParseLine method cannot contain more than one line.");
            }
            string         testString     = line.Trim();
            IniFileElement iniFileElement = null;

            if (IniFileBlankLine.IsLineValid(testString))
            {
                iniFileElement = new IniFileBlankLine(1);
            }
            else if (IniFileCommentary.IsLineValid(line))
            {
                iniFileElement = new IniFileCommentary(line);
            }
            else if (IniFileSectionStart.IsLineValid(testString))
            {
                iniFileElement = new IniFileSectionStart(line);
            }
            else if (IniFileValue.IsLineValid(testString))
            {
                iniFileElement = new IniFileValue(line);
            }
            return(iniFileElement ?? new IniFileElement(line));
        }
Beispiel #2
0
        public List <IniFileElement> ReadSection()
        {
            if (current == null || !(current is IniFileSectionStart))
            {
                throw new InvalidOperationException("The current position of the reader must be at IniFileSectionStart. Use GotoSection method");
            }
            List <IniFileElement> list = new List <IniFileElement>();
            IniFileElement        item = current;

            list.Add(item);
            string text = "";
            string text2;

            while ((text2 = ReadLine()) != null)
            {
                if (IniFileSectionStart.IsLineValid(text2.Trim()))
                {
                    current = new IniFileSectionStart(text2);
                    break;
                }
                text = text + text2 + Environment.NewLine;
            }
            if (text.EndsWith(Environment.NewLine) && text != Environment.NewLine)
            {
                text = text.Substring(0, text.Length - Environment.NewLine.Length);
            }
            list.AddRange(ParseText(text));
            return(list);
        }
Beispiel #3
0
        public IniFileValue GotoValue(string key, bool searchWholeFile)
        {
            string text;

            do
            {
                text = ReadLine();
                if (text == null)
                {
                    return(null);
                }
                if (IniFileValue.IsLineValid(text.Trim()))
                {
                    IniFileValue iniFileValue = ParseLine(text) as IniFileValue;
                    if (iniFileValue != null && (iniFileValue.Key == key || (!IniFileSettings.CaseSensitive && iniFileValue.Key.ToLowerInvariant() == key.ToLowerInvariant())))
                    {
                        return(iniFileValue);
                    }
                }
            }while (searchWholeFile || !IniFileSectionStart.IsLineValid(text.Trim()));
            return(null);
        }
Beispiel #4
0
        public IniFileSectionStart GotoSection(string sectionName)
        {
            IniFileSectionStart iniFileSectionStart = null;

            while (true)
            {
                string text = ReadLine();
                if (text == null)
                {
                    current = null;
                    return(null);
                }
                if (IniFileSectionStart.IsLineValid(text))
                {
                    iniFileSectionStart = (ParseLine(text) as IniFileSectionStart);
                    if (iniFileSectionStart != null && (iniFileSectionStart.SectionName == sectionName || (!IniFileSettings.CaseSensitive && iniFileSectionStart.SectionName.ToLowerInvariant() == sectionName)))
                    {
                        break;
                    }
                }
            }
            current = iniFileSectionStart;
            return(iniFileSectionStart);
        }