Пример #1
0
 public IniReader(IniOptions options)
 {
     this.options = options;
     this.currentEmptyLinesBefore = 0;
     this.currentTrailingComment  = null;
     this.currentSection          = null;
 }
Пример #2
0
        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;
        }
Пример #3
0
 // Deep copy constructor.
 internal IniComment(IniComment source)
 {
     this.text             = source.text;
     this.type             = source.type;
     this.EmptyLinesBefore = source.EmptyLinesBefore;
     this.LeftIndentation  = source.LeftIndentation;
 }
Пример #4
0
        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;
        }
Пример #5
0
 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();
     }
 }
Пример #6
0
 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;
     }
 }
Пример #7
0
        /* MZ(2015-08-29): Added support for section names that may contain end wrapper or comment starter characters. */
        private void ReadSection(int leftIndention, string line, IniFile file)
        {
            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;
        }
Пример #8
0
        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);
                }
            }
        }
Пример #9
0
        // 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);
            }
        }
Пример #10
0
 // Constructor used by IniReader.
 internal IniKey(IniFile parentFile, string name, IniComment trailingComment)
     : base(parentFile, name, trailingComment)
 {
 }
Пример #11
0
 // 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);
 }