< Summary

Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 88
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%
Read()100%1818100%

File(s)

https://raw.githubusercontent.com/JeremyAnsel/JeremyAnsel.Media.WavefrontObj/dbbfcd213b7c54f49194f82fcd56e790cca193c3/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
 8using System.Text;
 9
 10namespace JeremyAnsel.Media.WavefrontObj
 11{
 12    internal class LineReader
 13    {
 314        private static readonly char[] lineSeparators = new char[] { ' ', '\t' };
 15
 271816        public List<string> HeaderTextLines { get; } = new List<string>();
 17
 18        public IEnumerable<string[]> Read(Stream stream)
 19        {
 149120            using (var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true))
 21            {
 149122                string line = string.Empty;
 149123                bool isMultiLine = false;
 149124                bool readHeaderText = true;
 25
 462926                while (!reader.EndOfStream)
 27                {
 407128                    string? currentLine = reader.ReadLine();
 29
 407130                    if (string.IsNullOrWhiteSpace(currentLine))
 31                    {
 64532                        if (readHeaderText)
 33                        {
 64534                            this.HeaderTextLines.Add(string.Empty);
 35                        }
 36
 64537                        continue;
 38                    }
 39
 342640                    if (isMultiLine)
 41                    {
 1542                        line = line.Substring(0, line.Length - 1) + currentLine;
 43                    }
 44                    else
 45                    {
 341146                        line = currentLine;
 47                    }
 48
 342649                    line = line.Trim();
 50
 342651                    isMultiLine = line.EndsWith("\\", StringComparison.Ordinal);
 52
 342653                    if (isMultiLine)
 54                    {
 55                        continue;
 56                    }
 57
 341158                    int commentIndex = line.IndexOf('#');
 59
 341160                    if (commentIndex == 0)
 61                    {
 3062                        if (readHeaderText)
 63                        {
 2464                            this.HeaderTextLines.Add(line.Substring(1));
 65                        }
 66
 2467                        continue;
 68                    }
 69
 338170                    if (readHeaderText)
 71                    {
 148872                        readHeaderText = false;
 73                    }
 74
 338175                    if (commentIndex != -1)
 76                    {
 377                        line = line.Substring(0, commentIndex);
 78                    }
 79
 338180                    string[] values = line.Split(lineSeparators, StringSplitOptions.RemoveEmptyEntries);
 81
 338182                    yield return values;
 83                }
 55884            }
 55885        }
 86    }
 87}
 88