< Summary - Jellyfin

Information
Class: Emby.Naming.Video.Format3DParser
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/Video/Format3DParser.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 81
Line coverage: 100%
Branch coverage
93%
Covered branches: 15
Total branches: 16
Branch coverage: 93.7%
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
.cctor()100%11100%
Parse(...)100%11100%
Parse(...)100%44100%
Parse(...)91.66%1212100%

File(s)

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

#LineLine coverage
 1using System;
 2using Emby.Naming.Common;
 3
 4namespace Emby.Naming.Video
 5{
 6    /// <summary>
 7    /// Parse 3D format related flags.
 8    /// </summary>
 9    public static class Format3DParser
 10    {
 11        // Static default result to save on allocation costs.
 212        private static readonly Format3DResult _defaultResult = new(false, null);
 13
 14        /// <summary>
 15        /// Parse 3D format related flags.
 16        /// </summary>
 17        /// <param name="path">Path to file.</param>
 18        /// <param name="namingOptions">The naming options.</param>
 19        /// <returns>Returns <see cref="Format3DResult"/> object.</returns>
 20        public static Format3DResult Parse(ReadOnlySpan<char> path, NamingOptions namingOptions)
 21        {
 32522            int oldLen = namingOptions.VideoFlagDelimiters.Length;
 32523            Span<char> delimiters = stackalloc char[oldLen + 1];
 32524            namingOptions.VideoFlagDelimiters.AsSpan().CopyTo(delimiters);
 32525            delimiters[oldLen] = ' ';
 26
 32527            return Parse(path, delimiters, namingOptions);
 28        }
 29
 30        private static Format3DResult Parse(ReadOnlySpan<char> path, ReadOnlySpan<char> delimiters, NamingOptions naming
 31        {
 799732            foreach (var rule in namingOptions.Format3DRules)
 33            {
 368834                var result = Parse(path, rule, delimiters);
 35
 368836                if (result.Is3D)
 37                {
 2938                    return result;
 39                }
 40            }
 41
 29642            return _defaultResult;
 43        }
 44
 45        private static Format3DResult Parse(ReadOnlySpan<char> path, Format3DRule rule, ReadOnlySpan<char> delimiters)
 46        {
 368847            bool is3D = false;
 368848            string? format3D = null;
 49
 50            // If there's no preceding token we just consider it found
 368851            var foundPrefix = string.IsNullOrEmpty(rule.PrecedingToken);
 3317352            while (path.Length > 0)
 53            {
 2951454                var index = path.IndexOfAny(delimiters);
 2951455                if (index == -1)
 56                {
 365957                    index = path.Length - 1;
 58                }
 59
 2951460                var currentSlice = path[..index];
 2951461                path = path[(index + 1)..];
 62
 2951463                if (!foundPrefix)
 64                {
 999665                    foundPrefix = currentSlice.Equals(rule.PrecedingToken, StringComparison.OrdinalIgnoreCase);
 999666                    continue;
 67                }
 68
 1951869                is3D = foundPrefix && currentSlice.Equals(rule.Token, StringComparison.OrdinalIgnoreCase);
 70
 1951871                if (is3D)
 72                {
 2973                    format3D = rule.Token;
 2974                    break;
 75                }
 76            }
 77
 368878            return is3D ? new Format3DResult(true, format3D) : _defaultResult;
 79        }
 80    }
 81}