< Summary

Class:GDX.Developer.TextGenerator
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/TextGenerator.cs
Covered lines:52
Uncovered lines:0
Coverable lines:52
Total lines:139
Line coverage:100% (52 of 52)
Covered branches:0
Total branches:0
Covered methods:9
Total methods:9
Method coverage:100% (9 of 9)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TextGenerator(...)0%110100%
ApplyIndent()0%220100%
Append(...)0%110100%
AppendLine(...)0%110100%
AppendLineRange(...)0%330100%
NextLine()0%110100%
PopIndent()0%3.13077.78%
PushIndent(...)0%220100%
ToString()0%220100%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/TextGenerator.cs

#LineLine coverage
 1using System.Collections;
 2
 3namespace GDX.Developer
 4{
 5    /// <summary>
 6    ///     A formatted text generator useful for creating text based files with some semblance of organization.
 7    /// </summary>
 8    public class TextGenerator
 9    {
 10        /// <summary>
 11        ///     The actual buffer holder used to create the dynamic string.
 12        /// </summary>
 13        readonly System.Text.StringBuilder m_Builder;
 14        /// <summary>
 15        ///     The assigned indent content used to indent lines where applicable.
 16        /// </summary>
 17        readonly string m_IndentContent;
 18        /// <summary>
 19        ///     The content used to indicate the closing of a section that was indented.
 20        /// </summary>
 21        readonly string m_IndentClose;
 22        /// <summary>
 23        ///     The content used to indicate the opening of a section which should be indented.
 24        /// </summary>
 25        readonly string m_IndentOpen;
 26        /// <summary>
 27        ///     The current level of indentation.
 28        /// </summary>
 29        int m_IndentLevel;
 30
 31        /// <summary>
 32        ///     Create a new <see cref="TextGenerator"/> with the
 33        /// </summary>
 34        /// <param name="indentContent">
 35        ///     The characters used to indent the content when applicable. By default it will use a tab representation,
 36        ///     however for code files you may want to use four spaces.
 37        /// </param>
 38        /// <param name="indentOpen"></param>
 39        /// <param name="indentClose"></param>
 1340        public TextGenerator(string indentContent = "\t", string indentOpen = null, string indentClose = null)
 1341        {
 1342            m_IndentContent = indentContent;
 1343            m_IndentOpen = indentOpen;
 1344            m_IndentClose = indentClose;
 1345            m_Builder = new System.Text.StringBuilder();
 1346        }
 47
 48        /// <summary>
 49        ///     Apply the current level of indent to the current line being operated on.
 50        /// </summary>
 51        public void ApplyIndent()
 8252        {
 38053            for (int i = 0; i < m_IndentLevel; i++)
 10854            {
 10855                m_Builder.Append(m_IndentContent);
 10856            }
 8257        }
 58
 59        /// <summary>
 60        ///     Append content to the current line being operated on.
 61        /// </summary>
 62        /// <param name="content">The content to append to the current line.</param>
 63        public void Append(string content)
 7464        {
 7465            m_Builder.Append(content);
 7466        }
 67
 68        /// <summary>
 69        ///     Apply the appropriate amount of indentation to the current line, appending content afterwards and then
 70        ///     advancing to the next line.
 71        /// </summary>
 72        /// <param name="content">The content to append to the current line.</param>
 73        public void AppendLine(string content = "")
 4974        {
 4975            ApplyIndent();
 4976            m_Builder.AppendLine(content);
 4977        }
 78
 79        /// <summary>
 80        ///     Append an <see cref="IEnumerable"/> set of content as individual lines with proper indentation.
 81        /// </summary>
 82        /// <param name="content">The content to be added.</param>
 83        public void AppendLineRange(IEnumerable content)
 184        {
 785            foreach (string s in content)
 286            {
 287                ApplyIndent();
 288                m_Builder.AppendLine(s);
 289            }
 190        }
 91
 92        /// <summary>
 93        ///     Move the builder to the start of the next line.
 94        /// </summary>
 95        public void NextLine()
 1596        {
 1597            m_Builder.AppendLine();
 1598        }
 99
 100        /// <summary>
 101        ///     Remove a level of indentation from the builder.
 102        /// </summary>
 103        public void PopIndent()
 12104        {
 12105            if (m_IndentLevel <= 0) return;
 12106            m_IndentLevel--;
 16107            if (m_IndentOpen == null) return;
 8108            ApplyIndent();
 8109            m_Builder.AppendLine(m_IndentClose);
 12110        }
 111
 112        /// <summary>
 113        ///     Add a level of indentation to the builder.
 114        /// </summary>
 115        /// <param name="applyOpener">Should the opener be applied?</param>
 116        public void PushIndent(bool applyOpener = true)
 12117        {
 12118            if (m_IndentOpen != null && applyOpener)
 8119            {
 8120                ApplyIndent();
 8121                m_Builder.AppendLine(m_IndentOpen);
 8122            }
 12123            m_IndentLevel++;
 12124        }
 125
 126        /// <summary>
 127        ///     Returns the built string content for the builder.
 128        /// </summary>
 129        /// <remarks>Will automatically reduce the indentation level to 0.</remarks>
 130        public override string ToString()
 6131        {
 14132            while (m_IndentLevel > 0)
 8133            {
 8134                PopIndent();
 8135            }
 6136            return m_Builder.ToString().Trim();
 6137        }
 138    }
 139}