Exemplo n.º 1
0
 public IniReader(IniOptions options)
 {
     this.options = options;
     this.currentEmptyLinesBefore = 0;
     this.currentTrailingComment = null;
     this.currentSection = null;
 }
Exemplo n.º 2
0
 public IniReader(IniOptions options)
 {
     this.options = options;
     this.currentEmptyLinesBefore = 0;
     this.currentTrailingComment  = null;
     this.currentSection          = null;
 }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
 // Deep copy constructor.
 internal IniComment(IniComment source)
 {
     this.text             = source.text;
     this.type             = source.type;
     this.EmptyLinesBefore = source.EmptyLinesBefore;
     this.LeftIndentation  = source.LeftIndentation;
 }
Exemplo n.º 5
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);
                }

                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;
        }
Exemplo n.º 6
0
 // Deep copy constructor.
 internal IniComment(IniComment source)
 {
     this.text = source.text;
     this.type = source.type;
     this.EmptyLinesBefore = source.EmptyLinesBefore;
     this.LeftIndentation = source.LeftIndentation;
 }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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();
     }
 }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
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);
                }
            }
        }
Exemplo n.º 13
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;
     }
 }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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();
 }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
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);
 }
Exemplo n.º 20
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);

                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;
        }
Exemplo n.º 21
0
 // Constructor used by IniReader.
 internal IniKey(IniFile parentFile, string name, IniComment trailingComment)
     : base(parentFile, name, trailingComment)
 {
 }