public static IniElement 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."); } var trim = line.Trim(); IniElement elem = null; if (IniBlankLine.IsLineValid(trim)) { elem = new IniBlankLine(1); } else if (IniCommentary.IsLineValid(line)) { elem = new IniCommentary(line); } else if (IniSectionStart.IsLineValid(trim)) { elem = new IniSectionStart(line); } else if (IniValue.IsLineValid(trim)) { elem = new IniValue(line); } return(elem ?? new IniElement(line)); }
public List <IniElement> ReadSection() { if (_current == null || !(_current is IniSectionStart)) { throw new InvalidOperationException("The current position of the reader must be at IniSectionStart. Use GotoSection method"); } var ret = new List <IniElement>(); var theCurrent = _current; ret.Add(theCurrent); string text = "", temp; while ((temp = base.ReadLine()) != null) { if (IniSectionStart.IsLineValid(temp.Trim())) { _current = new IniSectionStart(temp); break; } text += temp + IniSettings.NewLine; } if (text.EndsWith(IniSettings.NewLine) && text != IniSettings.NewLine) { text = text.Substring(0, text.Length - IniSettings.NewLine.Length); } ret.AddRange(ParseText(text)); return(ret); }
public IniSectionStart GotoSection(string sectionName) { while (true) { var str = ReadLine(); if (str == null) { _current = null; return(null); } if (IniSectionStart.IsLineValid(str)) { var sect = ParseLine(str) as IniSectionStart; if (sect != null && (sect.SectionName == sectionName || (!IniSettings.CaseSensitive && sect.SectionName.ToLowerInvariant() == sectionName))) { _current = sect; return(sect); } } } }
public IniValue GotoValue(string key, bool searchWholeFile) { while (true) { var str = ReadLine(); if (str == null) { return(null); } if (IniValue.IsLineValid(str.Trim())) { var val = ParseLine(str) as IniValue; if (val != null && (val.Key == key || (!IniSettings.CaseSensitive && val.Key.ToLowerInvariant() == key.ToLowerInvariant()))) { return(val); } } if (!searchWholeFile && IniSectionStart.IsLineValid(str.Trim())) { return(null); } } }