Files
Umbraco-CMS/src/Umbraco.Tests/StringNewlineExtensions.cs
2017-09-20 20:06:46 +02:00

45 lines
1.5 KiB
C#

namespace Umbraco.Tests
{
static class StringNewLineExtensions
{
/// <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)
{
if (string.IsNullOrEmpty(text)) return text;
text = text.Replace("\r", ""); // remove CR
return text;
}
/// <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)) return text;
text = text.Replace("\r", ""); // remove CR
text = text.Replace("\n", "\r\n"); // add CRLF everywhere
return text;
}
/// <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)) return text;
text = text.Replace("\r\n", " "); // remove CRLF
text = text.Replace("\r", " "); // remove CR
text = text.Replace("\n", " "); // remove LF
return text;
}
}
}