2020-12-19 08:17:35 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Common.TestHelpers;
|
|
|
|
|
|
|
|
|
|
public static class StringNewLineExtensions
|
2015-03-06 14:06:32 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures Lf only everywhere.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">The text to filter.</param>
|
|
|
|
|
/// <returns>The filtered text.</returns>
|
|
|
|
|
public static string Lf(this string text)
|
2015-03-06 14:06:32 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
if (string.IsNullOrEmpty(text))
|
2015-03-06 14:06:32 +01:00
|
|
|
{
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
text = text.Replace("\r", string.Empty); // remove CR
|
|
|
|
|
return text;
|
|
|
|
|
}
|
2020-12-19 08:17:35 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures CrLf everywhere.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">The text to filter.</param>
|
|
|
|
|
/// <returns>The filtered text.</returns>
|
|
|
|
|
public static string CrLf(this string text)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(text))
|
|
|
|
|
{
|
2017-09-20 20:06:46 +02:00
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
text = text.Replace("\r", string.Empty); // remove CR
|
|
|
|
|
text = text.Replace("\n", "\r\n"); // add CRLF everywhere
|
|
|
|
|
return text;
|
|
|
|
|
}
|
2020-12-19 08:17:35 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Replaces Cr/Lf by a single space.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">The text to filter.</param>
|
|
|
|
|
/// <returns>The filtered text.</returns>
|
|
|
|
|
public static string NoCrLf(this string text)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(text))
|
|
|
|
|
{
|
2015-03-06 14:06:32 +01:00
|
|
|
return text;
|
|
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
|
|
|
|
|
text = text.Replace("\r\n", " "); // remove CRLF
|
|
|
|
|
text = text.Replace("\r", " "); // remove CR
|
|
|
|
|
text = text.Replace("\n", " "); // remove LF
|
|
|
|
|
return text;
|
2015-03-06 14:06:32 +01:00
|
|
|
}
|
|
|
|
|
}
|