mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-31 20:24:21 -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="str">The STR.</param>
|
||||||
/// <param name="attribute">The attrib.</param>
|
/// <param name="attribute">The attrib.</param>
|
||||||
/// <returns>System.String.</returns>
|
/// <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)
|
public static string? GetAttributeValue(this string str, string attribute)
|
||||||
{
|
{
|
||||||
if (str.Length == 0)
|
if (str.Length == 0)
|
||||||
|
@ -10,28 +10,28 @@ namespace MediaBrowser.Common.Extensions
|
|||||||
public static class StringExtensions
|
public static class StringExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the part left of the <c>needle</c>.
|
/// Returns the part on the left of the <c>needle</c>.
|
||||||
/// </summary>
|
/// </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="needle">The needle to find.</param>
|
||||||
/// <returns>The part left of the <c>needle</c>.</returns>
|
/// <returns>The part left of the <paramref name="needle" />.</returns>
|
||||||
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> str, char needle)
|
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, char needle)
|
||||||
{
|
{
|
||||||
var pos = str.IndexOf(needle);
|
var pos = haystack.IndexOf(needle);
|
||||||
return pos == -1 ? str : str[..pos];
|
return pos == -1 ? haystack : haystack[..pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the part left of the <c>needle</c>.
|
/// Returns the part on the left of the <c>needle</c>.
|
||||||
/// </summary>
|
/// </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="needle">The needle to find.</param>
|
||||||
/// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</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>
|
/// <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);
|
var pos = haystack.IndexOf(needle, stringComparison);
|
||||||
return pos == -1 ? str : str[..pos];
|
return pos == -1 ? haystack : haystack[..pos];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,29 +7,37 @@ namespace Jellyfin.Common.Tests.Extensions
|
|||||||
public class StringExtensionsTests
|
public class StringExtensionsTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
|
[InlineData("", 'q', "")]
|
||||||
[InlineData("Banana split", ' ', "Banana")]
|
[InlineData("Banana split", ' ', "Banana")]
|
||||||
[InlineData("Banana split", 'q', "Banana split")]
|
[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]
|
[Theory]
|
||||||
|
[InlineData("", "", "")]
|
||||||
|
[InlineData("", "q", "")]
|
||||||
|
[InlineData("Banana split", "", "")]
|
||||||
[InlineData("Banana split", " ", "Banana")]
|
[InlineData("Banana split", " ", "Banana")]
|
||||||
[InlineData("Banana split test", " 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]
|
[Theory]
|
||||||
|
[InlineData("", "", StringComparison.Ordinal, "")]
|
||||||
[InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
|
[InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
|
||||||
[InlineData("Banana split test", " 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", " Split", StringComparison.Ordinal, "Banana split test")]
|
||||||
[InlineData("Banana split test", " Splït", StringComparison.InvariantCultureIgnoreCase, "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 [imdbid=tt10985510]", "imdbid", "tt10985510")]
|
||||||
[InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
|
[InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
|
||||||
[InlineData("Superman: Red Son", "imdbid", null)]
|
[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]
|
[Theory]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user