public IniReader(IniOptions options) { this.options = options; this.currentEmptyLinesBefore = 0; this.currentTrailingComment = null; this.currentSection = null; }
private void ReadKey(int leftIndention, string line, IniFile file) { int keyDelimiterIndex = line.IndexOf((char)this.options.KeyDelimiter, leftIndention); if (keyDelimiterIndex != -1) { if (this.currentSection == null) { this.currentSection = file.Sections.Add(IniSection.GlobalSectionName); } /* MZ(2016-04-04): Fixed issue with trimming values. */ bool spacedDelimiter = keyDelimiterIndex > 0 && line[keyDelimiterIndex - 1] == ' '; string keyName = line.Substring(leftIndention, keyDelimiterIndex - leftIndention - (spacedDelimiter ? 1 : 0)); var currentKey = new IniKey(file, keyName, this.currentTrailingComment) { LeftIndentation = leftIndention, LeadingComment = { EmptyLinesBefore = this.currentEmptyLinesBefore } }; this.currentSection.Keys.Add(currentKey); ++keyDelimiterIndex; if (spacedDelimiter && keyDelimiterIndex < line.Length && line[keyDelimiterIndex] == ' ') { ++keyDelimiterIndex; } this.ReadValue(line.Substring(keyDelimiterIndex), currentKey); } this.currentTrailingComment = null; }
// Deep copy constructor. internal IniComment(IniComment source) { this.text = source.text; this.type = source.type; this.EmptyLinesBefore = source.EmptyLinesBefore; this.LeftIndentation = source.LeftIndentation; }
private void ReadKey(int leftIndention, string line, IniFile file) { int keyDelimiterIndex = line.IndexOf((char)this.options.KeyDelimiter, leftIndention); if (keyDelimiterIndex != -1) { if (this.currentSection == null) { this.currentSection = file.Sections.Add(IniSection.GlobalSectionName); } var currentKey = new IniKey(file, line.Substring(leftIndention, keyDelimiterIndex - leftIndention).TrimEnd(), this.currentTrailingComment) { LeftIndentation = leftIndention, LeadingComment = { EmptyLinesBefore = this.currentEmptyLinesBefore } }; this.currentSection.Keys.Add(currentKey); this.ReadKeyValueAndLeadingComment(line.Substring(++keyDelimiterIndex).TrimStart(), currentKey); } this.currentTrailingComment = null; }
internal IniItem(IniFile parentFile, string name, IniComment trailingComment = null) { if (name == null) throw new ArgumentNullException("name"); if (parentFile == null) throw new ArgumentNullException("parentFile"); this.name = name; this.parentFile = parentFile; this.trailingComment = trailingComment; }
private void ReadTrailingComment(int leftIndention, string text) { if (this.currentTrailingComment == null) this.currentTrailingComment = new IniComment(IniCommentType.Trailing) { EmptyLinesBefore = this.currentEmptyLinesBefore, LeftIndentation = leftIndention, Text = text }; else this.currentTrailingComment.Text += Environment.NewLine + text; }
internal IniItem(IniFile parentFile, string name, IniComment trailingComment = null) { if (name == null) { throw new ArgumentNullException("name"); } if (parentFile == null) { throw new ArgumentNullException("parentFile"); } this.name = name; this.parentFile = parentFile; this.trailingComment = trailingComment; }
private void WriteLeadingComment(IniComment leadingComment) { // E.g. " ;CommentText" if (leadingComment.Text != null) { this.writer.WriteLine( new String(' ', leadingComment.LeftIndentation) + (char)this.options.CommentStarter + leadingComment.Text); } else { this.writer.WriteLine(); } }
private void ReadSection(int leftIndention, string line, IniFile file) { /* MZ(2015-08-29): Added support for section names that may contain end wrapper or comment starter characters. */ int sectionEndIndex = -1, potentialCommentIndex, tempIndex = leftIndention; while (tempIndex != -1 && ++tempIndex <= line.Length) { potentialCommentIndex = line.IndexOf((char)this.options.CommentStarter, tempIndex); if (potentialCommentIndex != -1) { sectionEndIndex = line.LastIndexOf(this.options.sectionWrapperEnd, potentialCommentIndex - 1, potentialCommentIndex - tempIndex); } else { sectionEndIndex = line.LastIndexOf(this.options.sectionWrapperEnd, line.Length - 1, line.Length - tempIndex); } if (sectionEndIndex != -1) { break; } else { tempIndex = potentialCommentIndex; } } if (sectionEndIndex != -1) { this.currentSection = new IniSection(file, line.Substring(leftIndention + 1, sectionEndIndex - leftIndention - 1), this.currentTrailingComment) { LeftIndentation = leftIndention, LeadingComment = { EmptyLinesBefore = this.currentEmptyLinesBefore } }; file.Sections.Add(this.currentSection); if (++sectionEndIndex < line.Length) { this.ReadSectionLeadingComment(line.Substring(sectionEndIndex)); } } this.currentTrailingComment = null; }
private void WriteTrailingComment(IniComment trailingComment) { this.WriteEmptyLines(trailingComment.EmptyLinesBefore); // E.g. " ;CommentText // ;CommentText" if (trailingComment.Text != null) { foreach (string commentLine in trailingComment.Text.Split(IniWriter.NewLines, StringSplitOptions.None)) { this.writer.WriteLine( new String(' ', trailingComment.LeftIndentation) + (char)this.options.CommentStarter + commentLine); } } }
private void ReadTrailingComment(int leftIndention, string text) { if (this.currentTrailingComment == null) { this.currentTrailingComment = new IniComment(IniCommentType.Trailing) { EmptyLinesBefore = this.currentEmptyLinesBefore, LeftIndentation = leftIndention, Text = text } } ; else { this.currentTrailingComment.Text += Environment.NewLine + text; } }
// Deep copy constructor. internal IniItem(IniFile parentFile, IniItem sourceItem) { if (parentFile == null) { throw new ArgumentNullException("parentFile"); } this.name = sourceItem.name; this.parentFile = parentFile; if (sourceItem.HasLeadingComment) { this.leadingComment = new IniComment(sourceItem.leadingComment); } if (sourceItem.HasTrailingComment) { this.trailingComment = new IniComment(sourceItem.trailingComment); } }
private void WriteLeadingComment(IniComment leadingComment) { // E.g. " ;CommentText" if (leadingComment.Text != null) this.writer.WriteLine( new String(' ', leadingComment.LeftIndentation) + (char)this.options.CommentStarter + leadingComment.Text); else this.writer.WriteLine(); }
private void WriteTrailingComment(IniComment trailingComment) { this.WriteEmptyLines(trailingComment.EmptyLinesBefore); // E.g. " ;CommentText // ;CommentText" if (trailingComment.Text != null) foreach (string commentLine in trailingComment.Text.Split(IniWriter.NewLines, StringSplitOptions.None)) this.writer.WriteLine( new String(' ', trailingComment.LeftIndentation) + (char)this.options.CommentStarter + commentLine); }
// Deep copy constructor. internal IniItem(IniFile parentFile, IniItem sourceItem) { if (parentFile == null) throw new ArgumentNullException("parentFile"); this.name = sourceItem.name; this.parentFile = parentFile; if (sourceItem.HasLeadingComment) this.leadingComment = new IniComment(sourceItem.leadingComment); if (sourceItem.HasTrailingComment) this.trailingComment = new IniComment(sourceItem.trailingComment); }
private void ReadSection(int leftIndention, string line, IniFile file) { /* MZ(2015-08-29): Added support for section names that may contain end wrapper or comment starter characters. */ int sectionEndIndex = -1, potentialCommentIndex, tempIndex = leftIndention; while (tempIndex != -1 && ++tempIndex <= line.Length) { potentialCommentIndex = line.IndexOf((char)this.options.CommentStarter, tempIndex); if (potentialCommentIndex != -1) sectionEndIndex = line.LastIndexOf(this.options.sectionWrapperEnd, potentialCommentIndex - 1, potentialCommentIndex - tempIndex); else sectionEndIndex = line.LastIndexOf(this.options.sectionWrapperEnd, line.Length - 1, line.Length - tempIndex); if (sectionEndIndex != -1) break; else tempIndex = potentialCommentIndex; } if (sectionEndIndex != -1) { this.currentSection = new IniSection(file, line.Substring(leftIndention + 1, sectionEndIndex - leftIndention - 1), this.currentTrailingComment) { LeftIndentation = leftIndention, LeadingComment = { EmptyLinesBefore = this.currentEmptyLinesBefore } }; file.Sections.Add(this.currentSection); if (++sectionEndIndex < line.Length) this.ReadSectionLeadingComment(line.Substring(sectionEndIndex)); } this.currentTrailingComment = null; }
// Constructor used by IniReader. internal IniSection(IniFile parentFile, string name, IniComment trailingComment) : base(parentFile, name, trailingComment) { this.keys = new IniKeyCollection(parentFile, this, parentFile.options.KeyDuplicate, parentFile.options.KeyNameCaseSensitive); }
private void ReadKey(int leftIndention, string line, IniFile file) { int keyDelimiterIndex = line.IndexOf((char)this.options.KeyDelimiter, leftIndention); if (keyDelimiterIndex != -1) { if (this.currentSection == null) this.currentSection = file.Sections.Add(IniSection.GlobalSectionName); var currentKey = new IniKey(file, line.Substring(leftIndention, keyDelimiterIndex - leftIndention).TrimEnd(), this.currentTrailingComment) { LeftIndentation = leftIndention, LeadingComment = { EmptyLinesBefore = this.currentEmptyLinesBefore } }; this.currentSection.Keys.Add(currentKey); this.ReadKeyValueAndLeadingComment(line.Substring(++keyDelimiterIndex).TrimStart(), currentKey); } this.currentTrailingComment = null; }
// Constructor used by IniReader. internal IniKey(IniFile parentFile, string name, IniComment trailingComment) : base(parentFile, name, trailingComment) { }