Пример #1
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);
        }
Пример #2
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);
        }