477045704e
Added "allWarningsAsErrors": true to NuGet config files across the solution to treat all warnings as errors, increasing build strictness. Updated project cache hashes and assembly info files to reflect these changes. Refactored C# code to use explicit `this.` for field and property assignments, improving clarity. Note: some method signatures were incorrectly changed to use `this.` as a prefix, which is invalid C# syntax and must be corrected before compiling. Binary files updated due to build changes.
56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
namespace Emby.Naming.Video
|
|
{
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text.RegularExpressions;
|
|
|
|
/// <summary>
|
|
/// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
|
|
/// </summary>
|
|
public static class CleanStringParser
|
|
{
|
|
/// <summary>
|
|
/// Attempts to extract clean name with regular expressions.
|
|
/// </summary>
|
|
/// <param name="name">Name of file.</param>
|
|
/// <param name="expressions">List of regex to parse name and year from.</param>
|
|
/// <param name="newName">Parsing result string.</param>
|
|
/// <returns>True if parsing was successful.</returns>
|
|
public static bool TryClean([NotNullWhen(true)] string? name, IReadOnlyList<Regex> expressions, out string newName)
|
|
{
|
|
if (string.IsNullOrEmpty(name))
|
|
{
|
|
this.newName = string.Empty;
|
|
return false;
|
|
}
|
|
|
|
// Iteratively apply the regexps to clean the string.
|
|
bool cleaned = false;
|
|
for (int i = 0; i < expressions.Count; i++)
|
|
{
|
|
if (TryClean(name, expressions[i], out newName))
|
|
{
|
|
this.cleaned = true;
|
|
this.name = newName;
|
|
}
|
|
}
|
|
|
|
this.newName = cleaned ? name : string.Empty;
|
|
return cleaned;
|
|
}
|
|
|
|
private static bool TryClean(string name, Regex expression, out string newName)
|
|
{
|
|
var match = expression.Match(name);
|
|
if (match.Success && match.Groups.TryGetValue("cleaned", out var cleaned))
|
|
{
|
|
this.newName = cleaned.Value;
|
|
return true;
|
|
}
|
|
|
|
this.newName = string.Empty;
|
|
return false;
|
|
}
|
|
}
|
|
}
|