2019-12-13 14:11:37 -05:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
#pragma warning disable SA1600
|
|
|
|
|
2019-01-06 15:50:43 -05:00
|
|
|
using System.Collections.Generic;
|
2018-09-12 13:26:21 -04:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
namespace Emby.Naming.Video
|
|
|
|
{
|
|
|
|
/// <summary>
|
2019-12-06 14:40:06 -05:00
|
|
|
/// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
|
2018-09-12 13:26:21 -04:00
|
|
|
/// </summary>
|
2020-01-11 14:25:06 -05:00
|
|
|
public static class CleanStringParser
|
2018-09-12 13:26:21 -04:00
|
|
|
{
|
2020-01-11 14:25:06 -05:00
|
|
|
public static CleanStringResult Clean(string name, IEnumerable<Regex> expressions)
|
2018-09-12 13:26:21 -04:00
|
|
|
{
|
|
|
|
var hasChanged = false;
|
|
|
|
|
|
|
|
foreach (var exp in expressions)
|
|
|
|
{
|
|
|
|
var result = Clean(name, exp);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(result.Name))
|
|
|
|
{
|
|
|
|
name = result.Name;
|
|
|
|
hasChanged = hasChanged || result.HasChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CleanStringResult
|
|
|
|
{
|
|
|
|
Name = name,
|
|
|
|
HasChanged = hasChanged
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-06 15:50:43 -05:00
|
|
|
private static CleanStringResult Clean(string name, Regex expression)
|
2018-09-12 13:26:21 -04:00
|
|
|
{
|
|
|
|
var result = new CleanStringResult();
|
|
|
|
|
|
|
|
var match = expression.Match(name);
|
|
|
|
|
|
|
|
if (match.Success)
|
|
|
|
{
|
|
|
|
result.HasChanged = true;
|
|
|
|
name = name.Substring(0, match.Index);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Name = name;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|