core: remove string extensions in favor of explicit conversion (#7839)

This commit is contained in:
Cory 2020-03-24 21:39:38 -05:00 committed by GitHub
parent c18c0d574f
commit d7dddf6009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 27 additions and 37 deletions

View File

@ -211,7 +211,7 @@ namespace Jackett.Common.Indexers
var author = row.QuerySelector("dd.lastpost > span");
var timestr = author.TextContent.Split('\n')
.Where(str => !str.IsNullOrEmptyOrWhitespace()) //Filter blank lines
.Where(str => !string.IsNullOrWhiteSpace(str)) //Filter blank lines
.Skip(1) //Skip author name
.FirstOrDefault()
.Trim();

View File

@ -136,7 +136,7 @@ namespace Jackett.Common.Indexers
// If the search string is empty use the latest releases
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
=> query.IsTest || query.SearchTerm.IsNullOrEmptyOrWhitespace()
=> query.IsTest || string.IsNullOrWhiteSpace(query.SearchTerm)
? await FetchNewReleases()
: await PerformSearch(query);
@ -313,7 +313,7 @@ namespace Jackett.Common.Indexers
var releaseNode = tabNode.ParentElement;
var quality = GetQuality(releaseNode);
if (!quality.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(quality))
{
return $"{baseTitle} [{quality}]";
}
@ -324,7 +324,7 @@ namespace Jackett.Common.Indexers
private static string GetQuality(IElement releaseNode)
{
// For some releases there's no block with quality
if (releaseNode.Id.IsNullOrEmptyOrWhitespace())
if (string.IsNullOrWhiteSpace(releaseNode.Id))
{
return null;
}

View File

@ -47,7 +47,7 @@ namespace Jackett.Common.Indexers.Feeds
if (enclosures.Any())
{
var enclosure = enclosures.First().Attribute("url").Value;
release.Link = enclosure.ToUri();
release.Link = new Uri(enclosure);
}
// add some default values if none returned by feed
release.Seeders = release.Seeders > 0 ? release.Seeders : 0;

View File

@ -32,7 +32,7 @@ namespace Jackett.Common.Indexers.Feeds
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{
var requestUri = FeedUri.ToString();
if (!query.SearchTerm.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(query.SearchTerm))
requestUri = requestUri + "?q=" + query.SearchTerm;
var request = new WebRequest
{

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
@ -31,10 +32,10 @@ namespace Jackett.Common.Indexers.Feeds
var release = new ReleaseInfo
{
Title = item.FirstValue("title"),
Guid = item.FirstValue("guid").ToUri(),
Link = item.FirstValue("link").ToUri(),
Comments = item.FirstValue("comments").ToUri(),
PublishDate = item.FirstValue("pubDate").ToDateTime(),
Guid = new Uri(item.FirstValue("guid")),
Link = new Uri(item.FirstValue("link")),
Comments = new Uri(item.FirstValue("comments")),
PublishDate = DateTime.Parse(item.FirstValue("pubDate")),
Category = new List<int> { int.Parse(attributes.First(e => e.Attribute("name").Value == "category").Attribute("value").Value) },
Size = ReadAttribute(attributes, "size").TryParse<long>(),
Files = ReadAttribute(attributes, "files").TryParse<long>(),
@ -42,7 +43,7 @@ namespace Jackett.Common.Indexers.Feeds
Seeders = ReadAttribute(attributes, "seeders").TryParse<int>(),
Peers = ReadAttribute(attributes, "peers").TryParse<int>(),
InfoHash = attributes.First(e => e.Attribute("name").Value == "infohash").Attribute("value").Value,
MagnetUri = attributes.First(e => e.Attribute("name").Value == "magneturl").Attribute("value").Value.ToUri(),
MagnetUri = new Uri(attributes.First(e => e.Attribute("name").Value == "magneturl").Attribute("value").Value),
};
return release;
}

View File

@ -183,7 +183,7 @@ namespace Jackett.Common.Indexers
searchUrl += "?" + queryCollection.GetQueryString();
if (passkey.IsNullOrEmptyOrWhitespace())
if (string.IsNullOrWhiteSpace(passkey))
await ApplyConfiguration(null);
var result = await SendAPIRequest(searchUrl, null);

View File

@ -34,11 +34,11 @@ namespace Jackett.Common.Models.DTO
};
if (request.t != null)
query.QueryType = request.t;
if (!request.extended.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.extended))
query.Extended = ParseUtil.CoerceInt(request.extended);
if (!request.limit.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.limit))
query.Limit = ParseUtil.CoerceInt(request.limit);
if (!request.offset.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.offset))
query.Offset = ParseUtil.CoerceInt(request.offset);
if (request.cat != null)
@ -53,23 +53,23 @@ namespace Jackett.Common.Models.DTO
query.Categories = new int[0];
}
if (!request.rid.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.rid))
query.RageID = int.Parse(request.rid);
if (!request.season.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.season))
query.Season = int.Parse(request.season);
if (!request.album.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.album))
query.Album = request.album;
if (!request.artist.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.artist))
query.Artist = request.artist;
if (!request.label.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.label))
query.Label = request.label;
if (!request.track.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.track))
query.Track = request.track;
if (!request.year.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.year))
query.Year = int.Parse(request.year);
if (!request.genre.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(request.genre))
query.Genre = request.genre.Split(',');
query.ExpandCatsToSubCats();

View File

@ -159,7 +159,7 @@ namespace Jackett.Common.Services
var omdbApiKey = serverConfig.OmdbApiKey;
IFallbackStrategyProvider fallbackStrategyProvider = null;
IResultFilterProvider resultFilterProvider = null;
if (!omdbApiKey.IsNullOrEmptyOrWhitespace())
if (!string.IsNullOrWhiteSpace(omdbApiKey))
{
var imdbResolver = new OmdbResolver(webClient, omdbApiKey.ToNonNull(), serverConfig.OmdbApiUrl);
fallbackStrategyProvider = new ImdbFallbackStrategyProvider(imdbResolver);

View File

@ -48,17 +48,6 @@ namespace Jackett.Common.Utils
public static IEnumerable<T> Flatten<T>(this IEnumerable<IEnumerable<T>> list) => list.SelectMany(x => x);
}
// TODO This class should be removed in favor of explicit conversions
public static class StringExtension
{
// string.IsNullOrWhitespace already checks string.IsNullOrEmpty should remove this?
public static bool IsNullOrEmptyOrWhitespace(this string str) => string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str);
public static DateTime ToDateTime(this string str) => DateTime.Parse(str);
public static Uri ToUri(this string str) => new Uri(str);
}
public static class CollectionExtension
{
// IEnumerable class above already does this. All ICollection are IEnumerable, so favor IEnumerable?

View File

@ -39,7 +39,7 @@ namespace Jackett.Server.Controllers
}
var indexerId = parameters["indexerId"] as string;
if (indexerId.IsNullOrEmptyOrWhitespace())
if (string.IsNullOrWhiteSpace(indexerId))
return;
var indexerService = indexerController.IndexerService;

View File

@ -71,7 +71,7 @@ namespace Jackett.Server.Controllers
}
var indexerId = parameters["indexerId"] as string;
if (indexerId.IsNullOrEmptyOrWhitespace())
if (string.IsNullOrWhiteSpace(indexerId))
{
indexerController.CurrentIndexer = null;
context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.NotFound, 201, "Indexer is not specified (empty value)");