コード例 #1
0
ファイル: IniReader.cs プロジェクト: javadib/MadMilkman.Ini
 public IniReader(IniOptions options)
 {
     this.options = options;
     this.currentEmptyLinesBefore = 0;
     this.currentTrailingComment = null;
     this.currentSection = null;
 }
コード例 #2
0
 public IniReader(IniOptions options)
 {
     this.options = options;
     this.currentEmptyLinesBefore = 0;
     this.currentTrailingComment  = null;
     this.currentSection          = null;
 }
コード例 #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;
        }
コード例 #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;
 }
コード例 #5
0
ファイル: IniReader.cs プロジェクト: javadib/MadMilkman.Ini
        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;
        }
コード例 #6
0
ファイル: IniComment.cs プロジェクト: javadib/MadMilkman.Ini
 // Deep copy constructor.
 internal IniComment(IniComment source)
 {
     this.text = source.text;
     this.type = source.type;
     this.EmptyLinesBefore = source.EmptyLinesBefore;
     this.LeftIndentation = source.LeftIndentation;
 }
コード例 #7
0
ファイル: IniItem.cs プロジェクト: javadib/MadMilkman.Ini
        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;
        }
コード例 #8
0
ファイル: IniReader.cs プロジェクト: javadib/MadMilkman.Ini
 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;
 }
コード例 #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;
        }
コード例 #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();
     }
 }
コード例 #11
0
ファイル: IniReader.cs プロジェクト: javadib/MadMilkman.Ini
        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;
        }
コード例 #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);
                }
            }
        }
コード例 #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;
     }
 }
コード例 #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);
            }
        }
コード例 #15
0
ファイル: IniWriter.cs プロジェクト: javadib/MadMilkman.Ini
 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();
 }
コード例 #16
0
ファイル: IniWriter.cs プロジェクト: javadib/MadMilkman.Ini
        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);
        }
コード例 #17
0
ファイル: IniItem.cs プロジェクト: javadib/MadMilkman.Ini
        // 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);
        }
コード例 #18
0
ファイル: IniReader.cs プロジェクト: javadib/MadMilkman.Ini
        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;
        }
コード例 #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);
 }
コード例 #20
0
ファイル: IniReader.cs プロジェクト: javadib/MadMilkman.Ini
        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;
        }
コード例 #21
0
ファイル: IniKey.cs プロジェクト: vaveofficial/MadMilkman.Ini
 // Constructor used by IniReader.
 internal IniKey(IniFile parentFile, string name, IniComment trailingComment)
     : base(parentFile, name, trailingComment)
 {
 }