jellyfin/Emby.Naming/Video/CleanStringParser.cs

50 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2018-09-12 17:26:21 +00:00
using System.Text.RegularExpressions;
namespace Emby.Naming.Video
{
/// <summary>
/// http://kodi.wiki/view/Advancedsettings.xml#video
/// </summary>
public class CleanStringParser
{
public CleanStringResult Clean(string name, IEnumerable<Regex> expressions)
{
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
};
}
private static CleanStringResult Clean(string name, Regex expression)
2018-09-12 17:26:21 +00: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;
}
}
}