public bool TryGetProperty(string key, IniSectionData section, [NotNullWhen(true)] out IniLine <IniPropertyData>?property) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException("message", nameof(key)); } if (section == null) { throw new ArgumentNullException(nameof(section)); } if (!section.TryGetProperty(key, out var propertyData, out var offset)) { property = null; return(false); } var lineNumber = GetLineNumber(section, offset); property = new IniLine <IniPropertyData>(lineNumber, propertyData); return(true); }
public bool TryGetComment(string commentText, IniSectionData section, [NotNullWhen(true)] out IniLine <IniCommentData>?comment) { if (string.IsNullOrWhiteSpace(commentText)) { throw new ArgumentException("message", nameof(commentText)); } if (section == null) { throw new ArgumentNullException(nameof(section)); } if (!section.TryGetComment(commentText, out var commentData, out var offset)) { comment = null; return(false); } var lineNumber = GetLineNumber(section, offset); comment = new IniLine <IniCommentData>(lineNumber, commentData); return(true); }
private void Parse() { int currentLineNumber = 0; IniSectionData activeSection = Global; foreach (var line in _lines) { try { var matches = CommentRegex.Matches(line); if (matches.Count > 0) { IniCommentData iniComment = IniCommentData.FromLine(line); // We will discard any comments from before the first section activeSection.AddLine(iniComment); continue; } matches = PropertyRegex.Matches(line); if (matches.Count > 0) { var prop = new IniPropertyData(line); activeSection.AddLine(prop); continue; } matches = SectionRegex.Matches(line); if (matches.Count > 0) { var sectionName = matches[0].Groups[1].Value; activeSection = IniSectionData.FromLine(line); var iniSection = new IniLine <IniSectionData>(currentLineNumber, activeSection); _sections.Add(sectionName, iniSection); continue; } activeSection.AddLine(new IniEmptyLine()); } finally { currentLineNumber++; } } if (!TryGetProperty("root", Global, out var rootProp)) { return; } if (bool.TryParse(rootProp.Data.Value, out var isRoot)) { IsRoot = isRoot; } }
public bool TryGetSection(string name, [NotNullWhen(true)] out IniLine <IniSectionData>?section) => _sections.TryGetValue(name, out section);