Пример #1
0
        public static Dictionary <string, HashSet <string> > Parse(IEnumerable <string> lines)
        {
            SectionBuilder builder    = new SectionBuilder();
            int            lineNumber = 0;

            foreach (string t in lines)
            {
                lineNumber++;

                string currentLine = t.Trim();

                if (string.IsNullOrEmpty(currentLine))
                {
                    continue;                                     // ignore empty lines
                }
                if (currentLine.StartsWith("#"))
                {
                    continue;                                      // ignore comments
                }
                if (currentLine.StartsWith("[") && currentLine.EndsWith("]"))
                {
                    string sectionName = currentLine.Substring(1, currentLine.Length - 2);
                    ThrowIfContainsInvalidCharacters(sectionName, lineNumber);
                    builder.BeginSection(sectionName);
                }
                else
                {
                    builder.Add(currentLine, lineNumber);
                }
            }

            return(builder.Sections);
        }
Пример #2
0
        public static Dictionary<string, HashSet<string>> Parse(IEnumerable<string> lines)
        {
            SectionBuilder builder = new SectionBuilder();
            int lineNumber = 0;
            foreach (string t in lines)
            {
                lineNumber++;

                string currentLine = t.Trim();

                if (string.IsNullOrEmpty(currentLine)) continue;  // ignore empty lines
                if (currentLine.StartsWith("#")) continue;	   // ignore comments

                if (currentLine.StartsWith("[") && currentLine.EndsWith("]"))
                {
                    string sectionName = currentLine.Substring(1, currentLine.Length - 2);
                    ThrowIfContainsInvalidCharacters(sectionName, lineNumber);
                    builder.BeginSection(sectionName);
                }
                else
                {
                    builder.Add(currentLine, lineNumber);
                }
            }

            return builder.Sections;
        }