jellyfin/MediaBrowser.Common/Extensions/BaseExtensions.cs

38 lines
1.1 KiB
C#
Raw Normal View History

using System;
2019-12-11 00:13:57 +01:00
using System.Security.Cryptography;
using System.Text;
2018-12-28 00:27:57 +01:00
using System.Text.RegularExpressions;
namespace MediaBrowser.Common.Extensions
{
/// <summary>
2019-12-11 00:13:57 +01:00
/// Class BaseExtensions.
2018-12-28 00:27:57 +01:00
/// </summary>
2023-05-22 22:48:09 +02:00
public static partial class BaseExtensions
2018-12-28 00:27:57 +01:00
{
2023-05-22 22:48:09 +02:00
// http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
[GeneratedRegex(@"<(.|\n)*?>")]
private static partial Regex StripHtmlRegex();
2018-12-28 00:27:57 +01:00
/// <summary>
/// Strips the HTML.
/// </summary>
/// <param name="htmlString">The HTML string.</param>
2019-09-20 12:42:08 +02:00
/// <returns><see cref="string" />.</returns>
2018-12-28 00:27:57 +01:00
public static string StripHtml(this string htmlString)
2023-05-22 22:48:09 +02:00
=> StripHtmlRegex().Replace(htmlString, string.Empty).Trim();
2018-12-28 00:27:57 +01:00
/// <summary>
2019-09-20 12:42:08 +02:00
/// Gets the Md5.
2018-12-28 00:27:57 +01:00
/// </summary>
2019-09-20 12:42:08 +02:00
/// <param name="str">The string.</param>
/// <returns><see cref="Guid" />.</returns>
2018-12-28 00:27:57 +01:00
public static Guid GetMD5(this string str)
{
2019-12-11 00:13:57 +01:00
#pragma warning disable CA5351
return new Guid(MD5.HashData(Encoding.Unicode.GetBytes(str)));
2019-12-11 00:13:57 +01:00
#pragma warning restore CA5351
2018-12-28 00:27:57 +01:00
}
}
}