< Summary - Jellyfin

Information
Class: MediaBrowser.Model.Extensions.ContainerHelper
Assembly: MediaBrowser.Model
File(s): /srv/git/jellyfin/MediaBrowser.Model/Extensions/ContainerHelper.cs
Line coverage
96%
Covered lines: 32
Uncovered lines: 1
Coverable lines: 33
Total lines: 145
Line coverage: 96.9%
Branch coverage
91%
Covered branches: 31
Total branches: 34
Branch coverage: 91.1%
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
ContainsContainer(...)100%44100%
ContainsContainer(...)100%44100%
ContainsContainer(...)100%22100%
ContainsContainer(...)100%1212100%
ContainsContainer(...)87.5%8.09888.88%
Split(...)50%44100%

File(s)

/srv/git/jellyfin/MediaBrowser.Model/Extensions/ContainerHelper.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Jellyfin.Extensions;
 4
 5namespace MediaBrowser.Model.Extensions;
 6
 7/// <summary>
 8/// Defines the <see cref="ContainerHelper"/> class.
 9/// </summary>
 10public static class ContainerHelper
 11{
 12    /// <summary>
 13    /// Compares two containers, returning true if an item in <paramref name="inputContainer"/> exists
 14    /// in <paramref name="profileContainers"/>.
 15    /// </summary>
 16    /// <param name="profileContainers">The comma-delimited string being searched.
 17    /// If the parameter begins with the <c>-</c> character, the operation is reversed.</param>
 18    /// <param name="inputContainer">The comma-delimited string being matched.</param>
 19    /// <returns>The result of the operation.</returns>
 20    public static bool ContainsContainer(string? profileContainers, string? inputContainer)
 21    {
 730422        var isNegativeList = false;
 730423        if (profileContainers != null && profileContainers.StartsWith('-'))
 24        {
 1325            isNegativeList = true;
 1326            profileContainers = profileContainers[1..];
 27        }
 28
 730429        return ContainsContainer(profileContainers, isNegativeList, inputContainer);
 30    }
 31
 32    /// <summary>
 33    /// Compares two containers, returning true if an item in <paramref name="inputContainer"/> exists
 34    /// in <paramref name="profileContainers"/>.
 35    /// </summary>
 36    /// <param name="profileContainers">The comma-delimited string being searched.
 37    /// If the parameter begins with the <c>-</c> character, the operation is reversed.</param>
 38    /// <param name="inputContainer">The comma-delimited string being matched.</param>
 39    /// <returns>The result of the operation.</returns>
 40    public static bool ContainsContainer(string? profileContainers, ReadOnlySpan<char> inputContainer)
 41    {
 6342        var isNegativeList = false;
 6343        if (profileContainers != null && profileContainers.StartsWith('-'))
 44        {
 545            isNegativeList = true;
 546            profileContainers = profileContainers[1..];
 47        }
 48
 6349        return ContainsContainer(profileContainers, isNegativeList, inputContainer);
 50    }
 51
 52    /// <summary>
 53    /// Compares two containers, returning <paramref name="isNegativeList"/> if an item in <paramref name="inputContaine
 54    /// does not exist in <paramref name="profileContainers"/>.
 55    /// </summary>
 56    /// <param name="profileContainers">The comma-delimited string being searched.</param>
 57    /// <param name="isNegativeList">The boolean result to return if a match is not found.</param>
 58    /// <param name="inputContainer">The comma-delimited string being matched.</param>
 59    /// <returns>The result of the operation.</returns>
 60    public static bool ContainsContainer(string? profileContainers, bool isNegativeList, string? inputContainer)
 61    {
 819162        if (string.IsNullOrEmpty(inputContainer))
 63        {
 1164            return isNegativeList;
 65        }
 66
 818067        return ContainsContainer(profileContainers, isNegativeList, inputContainer.AsSpan());
 68    }
 69
 70    /// <summary>
 71    /// Compares two containers, returning <paramref name="isNegativeList"/> if an item in <paramref name="inputContaine
 72    /// does not exist in <paramref name="profileContainers"/>.
 73    /// </summary>
 74    /// <param name="profileContainers">The comma-delimited string being searched.</param>
 75    /// <param name="isNegativeList">The boolean result to return if a match is not found.</param>
 76    /// <param name="inputContainer">The comma-delimited string being matched.</param>
 77    /// <returns>The result of the operation.</returns>
 78    public static bool ContainsContainer(string? profileContainers, bool isNegativeList, ReadOnlySpan<char> inputContain
 79    {
 1054080        if (string.IsNullOrEmpty(profileContainers))
 81        {
 82            // Empty profiles always support all containers/codecs.
 343583            return true;
 84        }
 85
 710586        var allInputContainers = inputContainer.Split(',');
 710587        var allProfileContainers = profileContainers.SpanSplit(',');
 3107888        foreach (var container in allInputContainers)
 89        {
 995890            if (!container.IsEmpty)
 91            {
 4835092                foreach (var profile in allProfileContainers)
 93                {
 1574594                    if (!profile.IsEmpty && container.Equals(profile, StringComparison.OrdinalIgnoreCase))
 95                    {
 304896                        return !isNegativeList;
 97                    }
 98                }
 99            }
 100        }
 101
 4057102        return isNegativeList;
 103    }
 104
 105    /// <summary>
 106    /// Compares two containers, returning <paramref name="isNegativeList"/> if an item in <paramref name="inputContaine
 107    /// does not exist in <paramref name="profileContainers"/>.
 108    /// </summary>
 109    /// <param name="profileContainers">The profile containers being matched searched.</param>
 110    /// <param name="isNegativeList">The boolean result to return if a match is not found.</param>
 111    /// <param name="inputContainer">The comma-delimited string being matched.</param>
 112    /// <returns>The result of the operation.</returns>
 113    public static bool ContainsContainer(IReadOnlyList<string>? profileContainers, bool isNegativeList, string inputCont
 114    {
 164115        if (profileContainers is null)
 116        {
 117            // Empty profiles always support all containers/codecs.
 0118            return true;
 119        }
 120
 164121        var allInputContainers = Split(inputContainer);
 572122        foreach (var container in allInputContainers)
 123        {
 928124            foreach (var profile in profileContainers)
 125            {
 342126                if (string.Equals(profile, container, StringComparison.OrdinalIgnoreCase))
 127                {
 80128                    return !isNegativeList;
 129                }
 130            }
 131        }
 132
 84133        return isNegativeList;
 80134    }
 135
 136    /// <summary>
 137    /// Splits and input string.
 138    /// </summary>
 139    /// <param name="input">The input string.</param>
 140    /// <returns>The result of the operation.</returns>
 141    public static string[] Split(string? input)
 142    {
 742143        return input?.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? [];
 144    }
 145}