< Summary - Jellyfin

Information
Class: Emby.Naming.Video.CleanStringParser
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/Video/CleanStringParser.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 55
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryClean(...)100%88100%
TryClean(...)100%44100%

File(s)

/srv/git/jellyfin/Emby.Naming/Video/CleanStringParser.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Diagnostics.CodeAnalysis;
 3using System.Text.RegularExpressions;
 4
 5namespace Emby.Naming.Video
 6{
 7    /// <summary>
 8    /// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
 9    /// </summary>
 10    public static class CleanStringParser
 11    {
 12        /// <summary>
 13        /// Attempts to extract clean name with regular expressions.
 14        /// </summary>
 15        /// <param name="name">Name of file.</param>
 16        /// <param name="expressions">List of regex to parse name and year from.</param>
 17        /// <param name="newName">Parsing result string.</param>
 18        /// <returns>True if parsing was successful.</returns>
 19        public static bool TryClean([NotNullWhen(true)] string? name, IReadOnlyList<Regex> expressions, out string newNa
 20        {
 30021            if (string.IsNullOrEmpty(name))
 22            {
 923                newName = string.Empty;
 924                return false;
 25            }
 26
 27            // Iteratively apply the regexps to clean the string.
 29128            bool cleaned = false;
 407429            for (int i = 0; i < expressions.Count; i++)
 30            {
 174631                if (TryClean(name, expressions[i], out newName))
 32                {
 10033                    cleaned = true;
 10034                    name = newName;
 35                }
 36            }
 37
 29138            newName = cleaned ? name : string.Empty;
 29139            return cleaned;
 40        }
 41
 42        private static bool TryClean(string name, Regex expression, out string newName)
 43        {
 174644            var match = expression.Match(name);
 174645            if (match.Success && match.Groups.TryGetValue("cleaned", out var cleaned))
 46            {
 10047                newName = cleaned.Value;
 10048                return true;
 49            }
 50
 164651            newName = string.Empty;
 164652            return false;
 53        }
 54    }
 55}