jellyfin/MediaBrowser.Common/Extensions/BaseExtensions.cs

38 lines
1.1 KiB
C#
Raw Normal View History

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