You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/Emby.Naming/Video/CleanStringParser.cs

45 lines
1.2 KiB

#pragma warning disable CS1591
5 years ago
#nullable enable
5 years ago
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Emby.Naming.Video
{
/// <summary>
/// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
/// </summary>
public static class CleanStringParser
{
5 years ago
public static bool TryClean(string name, IReadOnlyList<Regex> expressions, out ReadOnlySpan<char> newName)
{
5 years ago
var len = expressions.Count;
for (int i = 0; i < len; i++)
{
5 years ago
if (TryClean(name, expressions[i], out newName))
{
5 years ago
return true;
}
}
5 years ago
newName = ReadOnlySpan<char>.Empty;
return false;
}
5 years ago
private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName)
{
var match = expression.Match(name);
5 years ago
int index = match.Index;
if (match.Success && index != 0)
{
5 years ago
newName = name.AsSpan().Slice(0, match.Index);
return true;
}
5 years ago
newName = string.Empty;
return false;
}
}
}