Exemple #1
0
        private void setComment(IniFileElement el, string comment)
        {
            int num = parent.elements.IndexOf(el);

            if (IniFileSettings.CommentChars.Length == 0)
            {
                throw new NotSupportedException("Comments are currently disabled. Setup ConfigFileSettings.CommentChars property to enable them.");
            }
            if (num > 0 && parent.elements[num - 1] is IniFileCommentary)
            {
                IniFileCommentary iniFileCommentary = (IniFileCommentary)parent.elements[num - 1];
                if (comment == "")
                {
                    parent.elements.Remove(iniFileCommentary);
                    return;
                }
                iniFileCommentary.Comment     = comment;
                iniFileCommentary.Intendation = el.Intendation;
            }
            else if (comment != "")
            {
                IniFileCommentary iniFileCommentary = IniFileCommentary.FromComment(comment);
                iniFileCommentary.Intendation = el.Intendation;
                parent.elements.Insert(num, iniFileCommentary);
            }
        }
Exemple #2
0
        public static IniFileElement ParseLine(string line)
        {
            if (line == null)
            {
                return(null);
            }
            if (line.Contains("\n"))
            {
                throw new ArgumentException("String passed to the ParseLine method cannot contain more than one line.");
            }
            string         testString     = line.Trim();
            IniFileElement iniFileElement = null;

            if (IniFileBlankLine.IsLineValid(testString))
            {
                iniFileElement = new IniFileBlankLine(1);
            }
            else if (IniFileCommentary.IsLineValid(line))
            {
                iniFileElement = new IniFileCommentary(line);
            }
            else if (IniFileSectionStart.IsLineValid(testString))
            {
                iniFileElement = new IniFileSectionStart(line);
            }
            else if (IniFileValue.IsLineValid(testString))
            {
                iniFileElement = new IniFileValue(line);
            }
            return(iniFileElement ?? new IniFileElement(line));
        }
Exemple #3
0
        public static IniFileCommentary FromComment(string comment)
        {
            if (IniFileSettings.CommentChars.Length == 0)
            {
                throw new NotSupportedException("Comments are disabled. Set the IniFileSettings.CommentChars property to turn them on.");
            }
            IniFileCommentary iniFileCommentary = new IniFileCommentary();

            iniFileCommentary.comment     = comment;
            iniFileCommentary.CommentChar = IniFileSettings.CommentChars[0];
            return(iniFileCommentary);
        }
Exemple #4
0
        public static List <IniFileElement> ParseText(string text)
        {
            if (text == null)
            {
                return(null);
            }
            List <IniFileElement> list           = new List <IniFileElement>();
            IniFileElement        iniFileElement = null;

            string[] array = text.Split(new string[1]
            {
                Environment.NewLine
            }, StringSplitOptions.None);
            for (int i = 0; i < array.Length; i++)
            {
                IniFileElement iniFileElement2 = ParseLine(array[i]);
                if (IniFileSettings.GroupElements)
                {
                    if (iniFileElement != null)
                    {
                        if (iniFileElement2 is IniFileBlankLine && iniFileElement is IniFileBlankLine)
                        {
                            ((IniFileBlankLine)iniFileElement).Amount++;
                            continue;
                        }
                        if (iniFileElement2 is IniFileCommentary && iniFileElement is IniFileCommentary)
                        {
                            IniFileCommentary obj = (IniFileCommentary)iniFileElement;
                            obj.Comment = obj.Comment + Environment.NewLine + ((IniFileCommentary)iniFileElement2).Comment;
                            continue;
                        }
                    }
                    else
                    {
                        iniFileElement = iniFileElement2;
                    }
                }
                iniFileElement = iniFileElement2;
                list.Add(iniFileElement2);
            }
            return(list);
        }
 /// <summary>Gets an IniFileCommentary object from commentary text.</summary>
 /// <param name="comment">Commentary text.</param>
 public static IniFileCommentary FromComment(string comment)
 {
     if (IniFileSettings.CommentChars.Length == 0)
         throw new NotSupportedException("Comments are disabled. Set the IniFileSettings.CommentChars property to turn them on.");
     IniFileCommentary ret = new IniFileCommentary();
     ret.comment = comment;
     ret.CommentChar = IniFileSettings.CommentChars[0];
     return ret;
 }
Exemple #6
0
 /// <summary>Parses a single line.</summary>
 /// <param name="line">Text to parse.</param>
 public static IniFileElement ParseLine(string line)
 {
     if (line == null)
         return null;
     if (line.Contains("\n"))
         throw new ArgumentException("String passed to the ParseLine method cannot contain more than one line.");
     string trim = line.Trim();
     IniFileElement elem = null;
     if (IniFileBlankLine.IsLineValid(trim))
         elem = new IniFileBlankLine(1);
     else if (IniFileCommentary.IsLineValid(line))
         elem = new IniFileCommentary(line);
     else if (IniFileSectionStart.IsLineValid(trim))
         elem = new IniFileSectionStart(line);
     else if (IniFileValue.IsLineValid(trim))
         elem = new IniFileValue(line);
     return elem ?? new IniFileElement(line);
 }