예제 #1
0
 public IniSectionStart(string content) : base(content)
 {
     //content = Content;
     formatting = ExtractFormat(content);
     content    = content.TrimStart();
     if (IniSettings.AllowInlineComments)
     {
         IniSettings.IndexOfAnyResult result = IniSettings.IndexOfAny(content, IniSettings.CommentChars);
         if (result.index > content.IndexOf(IniSettings.SectionCloseBracket))
         {
             inlineComment     = content.Substring(result.index + result.any.Length);
             inlineCommentChar = result.any;
             content           = content.Substring(0, result.index);
         }
     }
     if (IniSettings.AllowTextOnTheRight)
     {
         int closeBracketPos = content.LastIndexOf(IniSettings.SectionCloseBracket);
         if (closeBracketPos != content.Length - 1)
         {
             textOnTheRight = content.Substring(closeBracketPos + 1);
             content        = content.Substring(0, closeBracketPos);
         }
     }
     sectionName =
         content.Substring(IniSettings.SectionOpenBracket.Length,
                           content.Length - IniSettings.SectionCloseBracket.Length - IniSettings.SectionOpenBracket.Length).Trim();
     Content = content;
     Format();
 }
예제 #2
0
        public IniValue(string content)
            : base(content)
        {
            string[] split = Content.Split(new[] { IniSettings.EqualsString }, 2, StringSplitOptions.None);
            formatting = ExtractFormat(content);
            string split0 = split[0].Trim();
            string split1 = split.Length >= 1
                                ? split[1].Trim()
                                : "";

            if (split0.Length > 0)
            {
                if (IniSettings.AllowInlineComments)
                {
                    IniSettings.IndexOfAnyResult result = IniSettings.IndexOfAny(split1, IniSettings.CommentChars);
                    if (result.index != -1)
                    {
                        _inlineComment     = split1.Substring(result.index + result.any.Length);
                        split1             = split1.Substring(0, result.index).TrimEnd();
                        _inlineCommentChar = result.any;
                    }
                }
                if (IniSettings.QuoteChar != null && split1.Length >= 2)
                {
                    var quoteChar = (char)IniSettings.QuoteChar;
                    if (split1[0] == quoteChar)
                    {
                        int lastQuotePos;
                        if (IniSettings.AllowTextOnTheRight)
                        {
                            lastQuotePos = split1.LastIndexOf(quoteChar);
                            if (lastQuotePos != split1.Length - 1)
                            {
                                _textOnTheRight = split1.Substring(lastQuotePos + 1);
                            }
                        }
                        else
                        {
                            lastQuotePos = split1.Length - 1;
                        }
                        if (lastQuotePos > 0)
                        {
                            if (split1.Length == 2)
                            {
                                split1 = "";
                            }
                            else
                            {
                                split1 = split1.Substring(1, lastQuotePos - 1);
                            }
                        }
                    }
                }
                _key   = split0;
                _value = split1;
            }
            Format();
        }
예제 #3
0
 public IniCommentary(string content) : base(content)
 {
     if (IniSettings.CommentChars.Length == 0)
     {
         throw new NotSupportedException("Comments are disabled. Set the IniSettings.CommentChars property to turn them on.");
     }
     _commentChar = IniSettings.StartsWith(Content, IniSettings.CommentChars);
     _comment     = Content.Length > _commentChar.Length ? Content.Substring(_commentChar.Length) : "";
 }
예제 #4
0
        public string ExtractFormat(string content)
        {
            //IniSettings.DefaultValueFormatting
            var pos = FeState.BeforeEvery;
            var insideWhiteChars = "";

            var form = new StringBuilder();

            for (int i = 0; i < content.Length; i++)
            {
                var currC = content[i];
                if (char.IsLetterOrDigit(currC))
                {
                    if (pos == FeState.BeforeEvery)
                    {
                        form.Append('?');
                        pos = FeState.AfterKey;
                        //afterKey = true; beforeEvery = false; ;
                    }
                    else if (pos == FeState.BeforeVal)
                    {
                        form.Append('$');
                        pos = FeState.AfterVal;
                    }
                }

                else if (pos == FeState.AfterKey && content.Length - i >= IniSettings.EqualsString.Length &&
                         content.Substring(i, IniSettings.EqualsString.Length) == IniSettings.EqualsString)
                {
                    form.Append(insideWhiteChars);
                    pos = FeState.BeforeVal;
                    //afterKey = false; beforeVal = true;
                    form.Append('=');
                }
                else if ((IniSettings.OfAny(i, content, IniSettings.CommentChars)) != null)
                {
                    form.Append(insideWhiteChars);
                    form.Append(';');
                }
                else if (char.IsWhiteSpace(currC))
                {
                    string theWhiteChar;
                    if (currC == '\t' && IniSettings.TabReplacement != null)
                    {
                        theWhiteChar = IniSettings.TabReplacement;
                    }
                    else
                    {
                        theWhiteChar = currC.ToString();
                    }
                    if (pos == FeState.AfterKey || pos == FeState.AfterVal)
                    {
                        insideWhiteChars += theWhiteChar;
                        continue;
                    }
                    form.Append(theWhiteChar);
                }
                insideWhiteChars = "";
            }
            if (pos == FeState.BeforeVal)
            {
                form.Append('$');
                pos = FeState.AfterVal;
            }
            var ret = form.ToString();

            if (ret.IndexOf(';') == -1)
            {
                ret += "   ;";
            }
            return(ret);
        }
예제 #5
0
 public static bool IsLineValid(string testString)
 {
     return(IniSettings.StartsWith(testString.TrimStart(), IniSettings.CommentChars) != null);
 }
예제 #6
0
        public static string ExtractFormat(string content)
        {
            bool   beforeS     = false;
            bool   afterS      = false;
            bool   beforeEvery = true;
            char   currC;
            string comChar;
            string insideWhiteChars = "";
            var    form             = new StringBuilder();

            for (int i = 0; i < content.Length; i++)
            {
                currC = content[i];
                if (char.IsLetterOrDigit(currC) && beforeS)
                {
                    afterS  = true;
                    beforeS = false;
                    form.Append('$');
                }
                else if (afterS && char.IsLetterOrDigit(currC))
                {
                    insideWhiteChars = "";
                }
                else if (content.Length - i >= IniSettings.SectionOpenBracket.Length &&
                         content.Substring(i, IniSettings.SectionOpenBracket.Length) == IniSettings.SectionOpenBracket &&
                         beforeEvery)
                {
                    beforeS     = true;
                    beforeEvery = false;
                    form.Append('[');
                }
                else if (content.Length - i >= IniSettings.SectionCloseBracket.Length &&
                         content.Substring(i, IniSettings.SectionOpenBracket.Length) == IniSettings.SectionCloseBracket && afterS)
                {
                    form.Append(insideWhiteChars);
                    afterS = false;
                    form.Append(IniSettings.SectionCloseBracket);
                }
                else if ((comChar = IniSettings.OfAny(i, content, IniSettings.CommentChars)) != null)
                {
                    form.Append(';');
                }
                else if (char.IsWhiteSpace(currC))
                {
                    if (afterS)
                    {
                        insideWhiteChars += currC;
                    }
                    else
                    {
                        form.Append(currC);
                    }
                }
            }
            string ret = form.ToString();

            if (ret.IndexOf(';') == -1)
            {
                ret += "   ;";
            }
            return(ret);
        }