Exemple #1
0
 private int SortSectionsDelegate(IniSection a, IniSection b)
 {
     return(SortDelegate(a.Name, b.Name, SectionsStringComparison));
 }
Exemple #2
0
 private int SortSectionsDelegateRev(IniSection a, IniSection b)
 {
     return(SortSectionsDelegate(b, a));
 }
Exemple #3
0
        /// <summary>
        /// Loads the INI settings from the <paramref name="lines"/> specified.
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        public bool Load(List <string> lines)
        {
            if (lines == null)
            {
                throw new ArgumentNullException("lines");
            }

            IniSection    section = null;
            string        l;
            int           lineCount;
            char          lc;
            StringBuilder comments = new StringBuilder();

            Sections  = new IniSections();
            lineCount = 0;

            UnnamedSection = new IniSection("#unnamed");
            section        = UnnamedSection;
            bool inheader = true;

            for (int i = 0; i < lines.Count; i++)
            {
                l = lines[i].Trim();
                lineCount++;

                if (inheader)
                {
                    if (l.Length == 0)
                    {
                        comments.AppendLine("");
                        continue;
                    }
                    lc = l[0];
                    if (lc == '#')
                    {
                        comments.AppendLine(l);
                        continue;
                    }
                    else
                    {
                        UnnamedSection.Comments += comments.ToString();
                        comments.Clear();
                        inheader = false;
                    }
                }

                if (l.Length == 0)
                {
                    continue;
                }

                lc = l[0];

                if (lc == ';' || lc == '#')
                {
                    if (l.StartsWith("; ") || lc == '#')
                    {
                        // Comment
                        comments.AppendLine(l);
                    }
                    else
                    {
                        // Commented-out entry..
                        IniEntry entry = new IniEntry(l, "", IniEntryType.Comment, comments.ToString());
                        comments.Clear();
                        if (section == null)
                        {
                            UnnamedSection.Entries.Add(entry);
                        }
                        else
                        {
                            section.Entries.Add(entry);
                        }
                    }
                }
                else if (lc == '[')
                {
                    // handle the un-named items..
                    section = new IniSection(l, comments.ToString());
                    Sections.Add(section);
                    comments.Clear();
                }
                else if (l.Length > 0)
                {
                    if (l.IndexOf('=') == -1 && TreatPlainTextAsComment)
                    {
                        // plaintext
                        comments.Append("; **").AppendLine(l);
                    }
                    else
                    {
                        IniEntry entry = new IniEntry(l, comments.ToString(), TreatPlainTextAsComment);
                        comments.Clear();
                        if (section == null)
                        {
                            UnnamedSection.Entries.Add(entry);
                        }
                        else
                        {
                            section.Entries.Add(entry);
                        }
                    }
                }
            }

            return(true);
        }