namespace Spectre.Console.Testing;
///
/// Contains extensions for .
///
public static class StringExtensions
{
///
/// Returns a new string with all lines trimmed of trailing whitespace.
///
/// The string to trim.
/// A new string with all lines trimmed of trailing whitespace.
public static string TrimLines(this string value)
{
if (value is null)
{
return string.Empty;
}
var result = new List();
foreach (var line in value.NormalizeLineEndings().Split(new[] { '\n' }))
{
result.Add(line.TrimEnd());
}
return string.Join("\n", result);
}
///
/// Returns a new string with normalized line endings.
///
/// The string to normalize line endings for.
/// A new string with normalized line endings.
public static string NormalizeLineEndings(this string value)
{
if (value != null)
{
value = value.Replace("\r\n", "\n");
return value.Replace("\r", string.Empty);
}
return string.Empty;
}
}