mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Change ReadOnlySpan to string following PR 6383 (#6734)
This commit is contained in:
parent
1b478cfdec
commit
39d5bdac96
@ -17,11 +17,11 @@ namespace Emby.Naming.Video
|
|||||||
/// <param name="expressions">List of regex to parse name and year from.</param>
|
/// <param name="expressions">List of regex to parse name and year from.</param>
|
||||||
/// <param name="newName">Parsing result string.</param>
|
/// <param name="newName">Parsing result string.</param>
|
||||||
/// <returns>True if parsing was successful.</returns>
|
/// <returns>True if parsing was successful.</returns>
|
||||||
public static bool TryClean([NotNullWhen(true)] string? name, IReadOnlyList<Regex> expressions, out ReadOnlySpan<char> newName)
|
public static bool TryClean([NotNullWhen(true)] string? name, IReadOnlyList<Regex> expressions, out string newName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(name))
|
if (string.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
newName = ReadOnlySpan<char>.Empty;
|
newName = string.Empty;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,32 +32,24 @@ namespace Emby.Naming.Video
|
|||||||
if (TryClean(name, expressions[i], out newName))
|
if (TryClean(name, expressions[i], out newName))
|
||||||
{
|
{
|
||||||
cleaned = true;
|
cleaned = true;
|
||||||
name = newName.ToString();
|
name = newName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newName = cleaned ? name.AsSpan() : ReadOnlySpan<char>.Empty;
|
newName = cleaned ? name : string.Empty;
|
||||||
return cleaned;
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName)
|
private static bool TryClean(string name, Regex expression, out string newName)
|
||||||
{
|
{
|
||||||
var match = expression.Match(name);
|
var match = expression.Match(name);
|
||||||
int index = match.Index;
|
if (match.Success && match.Groups.TryGetValue("cleaned", out var cleaned))
|
||||||
if (match.Success)
|
|
||||||
{
|
{
|
||||||
var found = match.Groups.TryGetValue("cleaned", out var cleaned);
|
newName = cleaned.Value;
|
||||||
if (!found || cleaned == null)
|
|
||||||
{
|
|
||||||
newName = ReadOnlySpan<char>.Empty;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
newName = name.AsSpan().Slice(cleaned.Index, cleaned.Length);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
newName = ReadOnlySpan<char>.Empty;
|
newName = string.Empty;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,9 @@ namespace Emby.Naming.Video
|
|||||||
year = cleanDateTimeResult.Year;
|
year = cleanDateTimeResult.Year;
|
||||||
|
|
||||||
if (extraResult.ExtraType == null
|
if (extraResult.ExtraType == null
|
||||||
&& TryCleanString(name, namingOptions, out ReadOnlySpan<char> newName))
|
&& TryCleanString(name, namingOptions, out var newName))
|
||||||
{
|
{
|
||||||
name = newName.ToString();
|
name = newName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ namespace Emby.Naming.Video
|
|||||||
/// <param name="namingOptions">The naming options.</param>
|
/// <param name="namingOptions">The naming options.</param>
|
||||||
/// <param name="newName">Clean name.</param>
|
/// <param name="newName">Clean name.</param>
|
||||||
/// <returns>True if cleaning of name was successful.</returns>
|
/// <returns>True if cleaning of name was successful.</returns>
|
||||||
public static bool TryCleanString([NotNullWhen(true)] string? name, NamingOptions namingOptions, out ReadOnlySpan<char> newName)
|
public static bool TryCleanString([NotNullWhen(true)] string? name, NamingOptions namingOptions, out string newName)
|
||||||
{
|
{
|
||||||
return CleanStringParser.TryClean(name, namingOptions.CleanStringRegexes, out newName);
|
return CleanStringParser.TryClean(name, namingOptions.CleanStringRegexes, out newName);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using Emby.Naming.Common;
|
using Emby.Naming.Common;
|
||||||
using Emby.Naming.Video;
|
using Emby.Naming.Video;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@ -32,9 +31,8 @@ namespace Jellyfin.Naming.Tests.Video
|
|||||||
// FIXME: [InlineData("After The Sunset - [0004].mkv", "After The Sunset")]
|
// FIXME: [InlineData("After The Sunset - [0004].mkv", "After The Sunset")]
|
||||||
public void CleanStringTest_NeedsCleaning_Success(string input, string expectedName)
|
public void CleanStringTest_NeedsCleaning_Success(string input, string expectedName)
|
||||||
{
|
{
|
||||||
Assert.True(VideoResolver.TryCleanString(input, _namingOptions, out ReadOnlySpan<char> newName));
|
Assert.True(VideoResolver.TryCleanString(input, _namingOptions, out var newName));
|
||||||
// TODO: compare spans when XUnit supports it
|
Assert.Equal(expectedName, newName);
|
||||||
Assert.Equal(expectedName, newName.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -47,8 +45,8 @@ namespace Jellyfin.Naming.Tests.Video
|
|||||||
[InlineData("Run lola run (lola rennt) (2009).mp4")]
|
[InlineData("Run lola run (lola rennt) (2009).mp4")]
|
||||||
public void CleanStringTest_DoesntNeedCleaning_False(string? input)
|
public void CleanStringTest_DoesntNeedCleaning_False(string? input)
|
||||||
{
|
{
|
||||||
Assert.False(VideoResolver.TryCleanString(input, _namingOptions, out ReadOnlySpan<char> newName));
|
Assert.False(VideoResolver.TryCleanString(input, _namingOptions, out var newName));
|
||||||
Assert.True(newName.IsEmpty);
|
Assert.True(string.IsNullOrEmpty(newName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user