From 9cc42dce096fca98293bf9ccd5d3700b8a830cee Mon Sep 17 00:00:00 2001 From: Santiago Squarzon Date: Mon, 11 Sep 2023 20:57:12 -0300 Subject: [PATCH] improving Indent extension method --- src/PSTree/PSTreeExtensions.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/PSTree/PSTreeExtensions.cs b/src/PSTree/PSTreeExtensions.cs index 9b1df10..b4ee764 100644 --- a/src/PSTree/PSTreeExtensions.cs +++ b/src/PSTree/PSTreeExtensions.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System.Text; +using System.Text.RegularExpressions; namespace PSTree; @@ -6,8 +7,17 @@ internal static class PSTreeExtensions { private static readonly Regex s_re = new(@"└|\S", RegexOptions.Compiled); - internal static string Indent(this string inputString, int indentation) => - new string(' ', (4 * indentation) - 4) + "└── " + inputString; + private static readonly StringBuilder s_sb = new(); + + internal static string Indent(this string inputString, int indentation) + { + s_sb.Clear(); + + return s_sb.Append(' ', (4 * indentation) - 4) + .Append("└── ") + .Append(inputString) + .ToString(); + } internal static PSTreeFileSystemInfo[] ConvertToTree( this PSTreeFileSystemInfo[] inputObject)