1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-11 11:34:07 +02:00

Add StringUtils.NullIfEmpty & update existing code to use it

This commit is contained in:
chylex 2020-02-15 17:25:00 +01:00
parent aea77ff909
commit 447697ba45
2 changed files with 6 additions and 2 deletions
lib/TweetLib.Core
Features/Twitter
Utils

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using TweetLib.Core.Utils;
namespace TweetLib.Core.Features.Twitter{
public static class TwitterUrls{
@ -22,8 +23,7 @@ public static bool IsTwitterLogin2Factor(string url){
}
public static string? GetFileNameFromUrl(string url){
string file = Path.GetFileName(new Uri(url).AbsolutePath);
return string.IsNullOrEmpty(file) ? null : file;
return StringUtils.NullIfEmpty(Path.GetFileName(new Uri(url).AbsolutePath));
}
public static string GetMediaLink(string url, ImageQuality quality){

View File

@ -6,6 +6,10 @@ namespace TweetLib.Core.Utils{
public static class StringUtils{
public static readonly string[] EmptyArray = new string[0];
public static string? NullIfEmpty(string str){
return string.IsNullOrEmpty(str) ? null : str;
}
public static (string before, string after)? SplitInTwo(string str, char search, int startIndex = 0){
int index = str.IndexOf(search, startIndex);