mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Convert functions and properties to expression bodies when able (#7312)
Convert functions and properties to expression bodies when able
This commit is contained in:
@@ -15,10 +15,8 @@ namespace Jackett.Common.Utils
|
||||
{
|
||||
public static class StringUtil
|
||||
{
|
||||
public static string StripNonAlphaNumeric(this string str, string replacement = "")
|
||||
{
|
||||
return StripRegex(str, "[^a-zA-Z0-9 -]", replacement);
|
||||
}
|
||||
public static string StripNonAlphaNumeric(this string str, string replacement = "") =>
|
||||
StripRegex(str, "[^a-zA-Z0-9 -]", replacement);
|
||||
|
||||
public static string StripRegex(string str, string regex, string replacement = "")
|
||||
{
|
||||
@@ -43,26 +41,16 @@ namespace Jackett.Common.Utils
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
public static string FromBase64(string str)
|
||||
{
|
||||
return Encoding.UTF8.GetString(Convert.FromBase64String(str));
|
||||
}
|
||||
public static string FromBase64(string str) =>
|
||||
Encoding.UTF8.GetString(Convert.FromBase64String(str));
|
||||
|
||||
/// <summary>
|
||||
/// Convert an array of bytes to a string of hex digits
|
||||
/// </summary>
|
||||
/// <param name="bytes">array of bytes</param>
|
||||
/// <returns>String of hex digits</returns>
|
||||
public static string HexStringFromBytes(byte[] bytes)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var b in bytes)
|
||||
{
|
||||
var hex = b.ToString("x2");
|
||||
sb.Append(hex);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
public static string HexStringFromBytes(byte[] bytes) =>
|
||||
string.Join("", bytes.Select(b => b.ToString("X2")));
|
||||
|
||||
/// <summary>
|
||||
/// Compute hash for string encoded as UTF8
|
||||
@@ -90,6 +78,8 @@ namespace Jackett.Common.Utils
|
||||
return HexStringFromBytes(hashBytes);
|
||||
}
|
||||
|
||||
// Is never used
|
||||
// remove in favor of Exception.ToString() ?
|
||||
public static string GetExceptionDetails(this Exception exception)
|
||||
{
|
||||
var properties = exception.GetType()
|
||||
@@ -148,24 +138,15 @@ namespace Jackett.Common.Utils
|
||||
return changed ? sb.ToString() : text;
|
||||
}
|
||||
|
||||
public static string GetQueryString(this NameValueCollection collection, Encoding encoding = null)
|
||||
{
|
||||
if (encoding == null)
|
||||
encoding = Encoding.UTF8;
|
||||
return string.Join("&", collection.AllKeys.Select(a => a + "=" + WebUtilityHelpers.UrlEncode(collection[a], encoding)));
|
||||
}
|
||||
public static string GetQueryString(this NameValueCollection collection, Encoding encoding = null) =>
|
||||
string.Join("&", collection.AllKeys.Select(a =>
|
||||
$"{a}={WebUtilityHelpers.UrlEncode(collection[a], encoding ?? Encoding.UTF8)}"));
|
||||
|
||||
public static string GetQueryString(this ICollection<KeyValuePair<string, string>> collection, Encoding encoding = null)
|
||||
{
|
||||
if (encoding == null)
|
||||
encoding = Encoding.UTF8;
|
||||
return string.Join("&", collection.Select(a => a.Key + "=" + WebUtilityHelpers.UrlEncode(a.Value, encoding)));
|
||||
}
|
||||
public static string GetQueryString(this ICollection<KeyValuePair<string, string>> collection, Encoding encoding = null) =>
|
||||
string.Join("&", collection.Select(a =>
|
||||
$"{a.Key}={WebUtilityHelpers.UrlEncode(a.Value, encoding ?? Encoding.UTF8)}"));
|
||||
|
||||
public static void Add(this ICollection<KeyValuePair<string, string>> collection, string key, string value)
|
||||
{
|
||||
collection.Add(new KeyValuePair<string, string>(key, value));
|
||||
}
|
||||
public static void Add(this ICollection<KeyValuePair<string, string>> collection, string key, string value) => collection.Add(new KeyValuePair<string, string>(key, value));
|
||||
|
||||
public static string ToHtmlPretty(this IElement element)
|
||||
{
|
||||
|
Reference in New Issue
Block a user