< Summary

Information
Class: JeremyAnsel.Media.WavefrontObj.LineReader
Assembly: JeremyAnsel.Media.WavefrontObj
File(s): C:\projects\jeremyansel-media-wavefrontobj\JeremyAnsel.Media.WavefrontObj\JeremyAnsel.Media.WavefrontObj\LineReader.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 89
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_HeaderTextLines()100%11100%
.ctor()100%11100%
Read()100%1818100%

File(s)

C:\projects\jeremyansel-media-wavefrontobj\JeremyAnsel.Media.WavefrontObj\JeremyAnsel.Media.WavefrontObj\LineReader.cs

#LineLine coverage
 1// <copyright file="LineReader.cs" company="Jérémy Ansel">
 2// Copyright (c) 2017, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8#if !NET6_0_OR_GREATER
 9
 10using System.Text;
 11
 12namespace JeremyAnsel.Media.WavefrontObj
 13{
 14    internal class LineReader
 15    {
 116        public static readonly char[] LineSeparators = [' ', '\t'];
 17
 118        public List<string> HeaderTextLines { get; } = new List<string>();
 19
 20        public IEnumerable<string> Read(Stream stream)
 21        {
 122            using (var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true))
 23            {
 124                string line = string.Empty;
 125                bool isMultiLine = false;
 126                bool readHeaderText = true;
 27
 128                while (!reader.EndOfStream)
 29                {
 130                    string? currentLine = reader.ReadLine();
 31
 132                    if (string.IsNullOrWhiteSpace(currentLine))
 33                    {
 134                        if (readHeaderText)
 35                        {
 136                            this.HeaderTextLines.Add(string.Empty);
 37                        }
 38
 139                        continue;
 40                    }
 41
 142                    if (isMultiLine)
 43                    {
 144                        line = line.Substring(0, line.Length - 1) + currentLine;
 45                    }
 46                    else
 47                    {
 148                        line = currentLine;
 49                    }
 50
 151                    line = line.Trim();
 52
 153                    isMultiLine = line.EndsWith("\\", StringComparison.Ordinal);
 54
 155                    if (isMultiLine)
 56                    {
 57                        continue;
 58                    }
 59
 160                    int commentIndex = line.IndexOf('#');
 61
 162                    if (commentIndex == 0)
 63                    {
 164                        if (readHeaderText)
 65                        {
 166                            this.HeaderTextLines.Add(line.Substring(1));
 67                        }
 68
 169                        continue;
 70                    }
 71
 172                    if (readHeaderText)
 73                    {
 174                        readHeaderText = false;
 75                    }
 76
 177                    if (commentIndex != -1)
 78                    {
 179                        line = line.Substring(0, commentIndex);
 80                    }
 81
 182                    yield return line;
 83                }
 184            }
 185        }
 86    }
 87}
 88
 89#endif