コード例 #1
0
        public static IrbisTree ParseStream
        (
            [NotNull] TextReader reader
        )
        {
            IrbisTree result = new IrbisTree();

            List <Item> list = new List <Item>();
            string      line = reader.ReadLine();

            if (line == null)
            {
                goto DONE;
            }
            if (CountIndent(line) != 0)
            {
                throw new FormatException();
            }
            list.Add(new Item(line));

            int currentLevel = 0;

            while ((line = reader.ReadLine()) != null)
            {
                int level = CountIndent(line);
                if (level > (currentLevel + 1))
                {
                    throw new FormatException();
                }
                currentLevel = level;
                line         = line.TrimStart(Indent);
                Item item = new Item(line)
                {
                    _level = currentLevel
                };
                list.Add(item);
            }

            int maxLevel = list.Max(item => item._level);

            for (int level = 0; level < maxLevel; level++)
            {
                _ArrangeLevel(list, level);
            }

            var roots = list.Where(item => item._level == 0);

            result.Roots.AddRange(roots);

DONE:
            return(result);
        }
コード例 #2
0
        public static IrbisTree ReadLocalFile
        (
            [NotNull] string fileName,
            [NotNull] Encoding encoding
        )
        {
            using (StreamReader reader
                       = new StreamReader
                         (
                             File.OpenRead(fileName),
                             encoding
                         ))
            {
                IrbisTree result = ParseStream(reader);
                result.FileName = Path.GetFileName(fileName);

                return(result);
            }
        }