Example #1
0
 /// <summary>Initializes a new instance IniFileSectionStart</summary>
 /// <param name="content">Actual content of a line in an INI file. Initializer assumes that it is valid.</param>
 public IniFileSectionStart(string content) : base(content)
 {
     fFormatting = ExtractFormat(content);
     content     = content.TrimStart();
     if (IniFileEx.AllowInlineComments)
     {
         IndexOfAnyResult result = IndexOfAny(content, IniFileEx.CommentChars);
         if (result.Index > content.IndexOf(IniFileEx.SectionCloseBracket))
         {
             fInlineComment = content.Substring(result.Index + result.Any.Length);
             content        = content.Substring(0, result.Index);
         }
     }
     if (IniFileEx.AllowTextOnTheRight)
     {
         int closeBracketPos = content.LastIndexOf(IniFileEx.SectionCloseBracket);
         if (closeBracketPos != content.Length - 1)
         {
             fTextOnTheRight = content.Substring(closeBracketPos + 1);
             content         = content.Substring(0, closeBracketPos);
         }
     }
     fSectionName = content.Substring(IniFileEx.SectionOpenBracket.Length, content.Length - IniFileEx.SectionCloseBracket.Length - IniFileEx.SectionOpenBracket.Length).Trim();
     Content      = content;
     Format();
 }
Example #2
0
        /// <summary>Initializes a new instance IniFileValue.</summary>
        /// <param name="content">Actual content of a line in an INI file. Initializer assumes that it is valid.</param>
        public IniFileValue(string content) : base(content)
        {
            string[] split = Content.Split(new string[] { IniFileEx.EqualsString }, StringSplitOptions.None);
            fFormatting = ExtractFormat(content);
            string split0 = split[0].Trim();
            string split1 = split.Length >= 1 ? split[1].Trim() : "";

            if (split0.Length > 0)
            {
                if (IniFileEx.AllowInlineComments)
                {
                    IndexOfAnyResult result = IndexOfAny(split1, IniFileEx.CommentChars);
                    if (result.Index != -1)
                    {
                        fInlineComment     = split1.Substring(result.Index + result.Any.Length);
                        split1             = split1.Substring(0, result.Index).TrimEnd();
                        fInlineCommentChar = result.Any;
                    }
                }
                if (IniFileEx.QuoteChar != null && split1.Length >= 2)
                {
                    char quoteChar = (char)IniFileEx.QuoteChar;
                    if (split1[0] == quoteChar)
                    {
                        int lastQuotePos;
                        if (IniFileEx.AllowTextOnTheRight)
                        {
                            lastQuotePos = split1.LastIndexOf(quoteChar);
                            if (lastQuotePos != split1.Length - 1)
                            {
                                fTextOnTheRight = split1.Substring(lastQuotePos + 1);
                            }
                        }
                        else
                        {
                            lastQuotePos = split1.Length - 1;
                        }

                        if (lastQuotePos > 0)
                        {
                            split1 = (split1.Length == 2) ? "" : split1.Substring(1, lastQuotePos - 1);
                        }
                    }
                }
                fKey   = split0;
                fValue = split1;
            }
            Format();
        }