Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 114 additions & 2 deletions Src/CSharpier.Benchmarks/Program.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions Src/CSharpier.Core/Utilities/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Runtime.CompilerServices;

namespace CSharpier.Core.Utilities;

internal static class StringExtensions
Expand Down Expand Up @@ -35,7 +37,20 @@ public static int IndexOf(this string value, char otherValue)
#endif

// some unicode characters should be considered size of 2 when calculating how big this string will be when printed
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetPrintedWidth(this string value)
{
#if NET8_0_OR_GREATER
if (! MemoryExtensions.ContainsAnyExceptInRange(value, (char)0, (char)0x10FF))
{
return value.Length;
}
#endif

return CalculateActualWidth(value);
}

private static int CalculateActualWidth(string value)
{
var sum = 0;
// ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
Expand Down
Loading