mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-12-28 08:48:03 +01:00
Added initial support for rendering composites
This is far from complete, but it's a start and it will enable us to create things like tables and other complex objects in the long run.
This commit is contained in:
committed by
Patrik Svensson
parent
e596e6eb4f
commit
8e4f33bba4
36
src/Spectre.Console/Internal/Extensions/StringExtensions.cs
Normal file
36
src/Spectre.Console/Internal/Extensions/StringExtensions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal static class StringExtensions
|
||||
{
|
||||
// Cache whether or not internally normalized line endings
|
||||
// already are normalized. No reason to do yet another replace if it is.
|
||||
private static readonly bool _alreadyNormalized
|
||||
= Environment.NewLine.Equals("\n", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public static int CellLength(this string text, Encoding encoding)
|
||||
{
|
||||
return Cell.GetCellLength(encoding, text);
|
||||
}
|
||||
|
||||
public static string NormalizeLineEndings(this string text, bool native = false)
|
||||
{
|
||||
var normalized = text?.Replace("\r\n", "\n")
|
||||
?.Replace("\r", string.Empty);
|
||||
|
||||
if (native && !_alreadyNormalized)
|
||||
{
|
||||
normalized = normalized.Replace("\n", Environment.NewLine);
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
public static string[] SplitLines(this string text)
|
||||
{
|
||||
return text.NormalizeLineEndings().Split(new[] { '\n' }, StringSplitOptions.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user