mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-24 02:02:29 -04:00
Address comments
This commit is contained in:
parent
958681cdff
commit
c430a7ed8f
@ -16,7 +16,7 @@ namespace Emby.Server.Implementations.Library
|
||||
/// <param name="str">The STR.</param>
|
||||
/// <param name="attribute">The attrib.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
/// <exception cref="ArgumentException"><c>str</c> or <c>attribute</c> is empty.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="str" /> or <paramref name="attribute" /> is empty.</exception>
|
||||
public static string? GetAttributeValue(this string str, string attribute)
|
||||
{
|
||||
if (str.Length == 0)
|
||||
|
@ -10,28 +10,28 @@ namespace MediaBrowser.Common.Extensions
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the part left of the <c>needle</c>.
|
||||
/// Returns the part on the left of the <c>needle</c>.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to seek.</param>
|
||||
/// <param name="haystack">The string to seek.</param>
|
||||
/// <param name="needle">The needle to find.</param>
|
||||
/// <returns>The part left of the <c>needle</c>.</returns>
|
||||
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> str, char needle)
|
||||
/// <returns>The part left of the <paramref name="needle" />.</returns>
|
||||
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, char needle)
|
||||
{
|
||||
var pos = str.IndexOf(needle);
|
||||
return pos == -1 ? str : str[..pos];
|
||||
var pos = haystack.IndexOf(needle);
|
||||
return pos == -1 ? haystack : haystack[..pos];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the part left of the <c>needle</c>.
|
||||
/// Returns the part on the left of the <c>needle</c>.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to seek.</param>
|
||||
/// <param name="haystack">The string to seek.</param>
|
||||
/// <param name="needle">The needle to find.</param>
|
||||
/// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</param>
|
||||
/// <returns>The part left of the <c>needle</c>.</returns>
|
||||
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> str, ReadOnlySpan<char> needle, StringComparison stringComparison = default)
|
||||
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, ReadOnlySpan<char> needle, StringComparison stringComparison = default)
|
||||
{
|
||||
var pos = str.IndexOf(needle, stringComparison);
|
||||
return pos == -1 ? str : str[..pos];
|
||||
var pos = haystack.IndexOf(needle, stringComparison);
|
||||
return pos == -1 ? haystack : haystack[..pos];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,29 +7,37 @@ namespace Jellyfin.Common.Tests.Extensions
|
||||
public class StringExtensionsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("", 'q', "")]
|
||||
[InlineData("Banana split", ' ', "Banana")]
|
||||
[InlineData("Banana split", 'q', "Banana split")]
|
||||
public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string result)
|
||||
public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string expectedResult)
|
||||
{
|
||||
Assert.Equal(result, str.AsSpan().LeftPart(needle).ToString());
|
||||
var result = str.AsSpan().LeftPart(needle).ToString();
|
||||
Assert.Equal(expectedResult, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "", "")]
|
||||
[InlineData("", "q", "")]
|
||||
[InlineData("Banana split", "", "")]
|
||||
[InlineData("Banana split", " ", "Banana")]
|
||||
[InlineData("Banana split test", " split", "Banana")]
|
||||
public void LeftPart_ValidArgsWithoutStringComparison_Correct(string str, string needle, string result)
|
||||
public void LeftPart_ValidArgsWithoutStringComparison_Correct(string str, string needle, string expectedResult)
|
||||
{
|
||||
Assert.Equal(result, str.AsSpan().LeftPart(needle).ToString());
|
||||
var result = str.AsSpan().LeftPart(needle).ToString();
|
||||
Assert.Equal(expectedResult, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "", StringComparison.Ordinal, "")]
|
||||
[InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
|
||||
[InlineData("Banana split test", " split", StringComparison.Ordinal, "Banana")]
|
||||
[InlineData("Banana split test", " Split", StringComparison.Ordinal, "Banana split test")]
|
||||
[InlineData("Banana split test", " Splït", StringComparison.InvariantCultureIgnoreCase, "Banana split test")]
|
||||
public void LeftPart_ValidArgs_Correct(string str, string needle, StringComparison stringComparison, string result)
|
||||
public void LeftPart_ValidArgs_Correct(string str, string needle, StringComparison stringComparison, string expectedResult)
|
||||
{
|
||||
Assert.Equal(result, str.AsSpan().LeftPart(needle, stringComparison).ToString());
|
||||
var result = str.AsSpan().LeftPart(needle, stringComparison).ToString();
|
||||
Assert.Equal(expectedResult, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ namespace Jellyfin.Server.Implementations.Tests.Library
|
||||
[InlineData("Superman: Red Son [imdbid=tt10985510]", "imdbid", "tt10985510")]
|
||||
[InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
|
||||
[InlineData("Superman: Red Son", "imdbid", null)]
|
||||
public void GetAttributeValue_ValidArgs_Correct(string input, string attribute, string? result)
|
||||
public void GetAttributeValue_ValidArgs_Correct(string input, string attribute, string? expectedResult)
|
||||
{
|
||||
Assert.Equal(result, PathExtensions.GetAttributeValue(input, attribute));
|
||||
Assert.Equal(expectedResult, PathExtensions.GetAttributeValue(input, attribute));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
Loading…
x
Reference in New Issue
Block a user