2019-12-13 20:11:37 +01:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
#pragma warning disable SA1600
|
2020-01-11 21:16:36 +01:00
|
|
|
#nullable enable
|
2019-12-13 20:11:37 +01:00
|
|
|
|
2020-01-11 21:16:36 +01:00
|
|
|
using System;
|
2019-01-06 21:50:43 +01:00
|
|
|
using System.Collections.Generic;
|
2018-09-12 19:26:21 +02:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
namespace Emby.Naming.Video
|
|
|
|
{
|
|
|
|
/// <summary>
|
2019-12-06 20:40:06 +01:00
|
|
|
/// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
|
2018-09-12 19:26:21 +02:00
|
|
|
/// </summary>
|
2020-01-11 20:25:06 +01:00
|
|
|
public static class CleanStringParser
|
2018-09-12 19:26:21 +02:00
|
|
|
{
|
2020-01-11 21:16:36 +01:00
|
|
|
public static bool TryClean(string name, IReadOnlyList<Regex> expressions, out ReadOnlySpan<char> newName)
|
2018-09-12 19:26:21 +02:00
|
|
|
{
|
2020-01-11 21:16:36 +01:00
|
|
|
var len = expressions.Count;
|
|
|
|
for (int i = 0; i < len; i++)
|
2018-09-12 19:26:21 +02:00
|
|
|
{
|
2020-01-11 21:16:36 +01:00
|
|
|
if (TryClean(name, expressions[i], out newName))
|
2018-09-12 19:26:21 +02:00
|
|
|
{
|
2020-01-11 21:16:36 +01:00
|
|
|
return true;
|
2018-09-12 19:26:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 21:16:36 +01:00
|
|
|
newName = ReadOnlySpan<char>.Empty;
|
|
|
|
return false;
|
2018-09-12 19:26:21 +02:00
|
|
|
}
|
|
|
|
|
2020-01-11 21:16:36 +01:00
|
|
|
private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName)
|
2018-09-12 19:26:21 +02:00
|
|
|
{
|
|
|
|
var match = expression.Match(name);
|
2020-01-11 21:16:36 +01:00
|
|
|
int index = match.Index;
|
|
|
|
if (match.Success && index != 0)
|
2018-09-12 19:26:21 +02:00
|
|
|
{
|
2020-01-11 21:16:36 +01:00
|
|
|
newName = name.AsSpan().Slice(0, match.Index);
|
|
|
|
return true;
|
2018-09-12 19:26:21 +02:00
|
|
|
}
|
|
|
|
|
2020-01-11 21:16:36 +01:00
|
|
|
newName = string.Empty;
|
|
|
|
return false;
|
2018-09-12 19:26:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|